当前位置: 技术问答>java相关
一个java程序,怎么写不进去?等待……
来源: 互联网 发布时间:2015-10-31
本文导语: 我想把c.java 写进e.java ,然后在做些其他的操作,怎么写不进去? import java.io.*; public class str{ public static void main(String agrs[]){ try { FileInputStream is; InputStreamReader ir; BufferedReader in; FileOutputStream it; O...
我想把c.java 写进e.java ,然后在做些其他的操作,怎么写不进去?
import java.io.*;
public class str{
public static void main(String agrs[]){
try
{
FileInputStream is;
InputStreamReader ir;
BufferedReader in;
FileOutputStream it;
OutputStreamWriter iu;
BufferedWriter out;
is = new FileInputStream ("g:\c.java");
ir=new InputStreamReader(is);
in=new BufferedReader(ir);
it = new FileOutputStream ("g:\e.java");
iu=new OutputStreamWriter (it);
out = new BufferedWriter(iu);
copyFile(in,out);
}catch(FileNotFoundException e){
System.out.println("file is not found");
System.exit(-2);
}
catch(IOException e){
System.out.println("error"+e);
System.exit(-3);
}
}
private static void copyFile(BufferedReader in,BufferedWriter out)
{
int length;
String s;
//byte buf[]=new byte[1000];
try{
while((s=in.readLine())!=null)
out.write(s);
}catch(IOException e){
System.out.println("error"+e);
System.exit(-4);
}
}
}
import java.io.*;
public class str{
public static void main(String agrs[]){
try
{
FileInputStream is;
InputStreamReader ir;
BufferedReader in;
FileOutputStream it;
OutputStreamWriter iu;
BufferedWriter out;
is = new FileInputStream ("g:\c.java");
ir=new InputStreamReader(is);
in=new BufferedReader(ir);
it = new FileOutputStream ("g:\e.java");
iu=new OutputStreamWriter (it);
out = new BufferedWriter(iu);
copyFile(in,out);
}catch(FileNotFoundException e){
System.out.println("file is not found");
System.exit(-2);
}
catch(IOException e){
System.out.println("error"+e);
System.exit(-3);
}
}
private static void copyFile(BufferedReader in,BufferedWriter out)
{
int length;
String s;
//byte buf[]=new byte[1000];
try{
while((s=in.readLine())!=null)
out.write(s);
}catch(IOException e){
System.out.println("error"+e);
System.exit(-4);
}
}
}
|
import java.io.*;
public class str{
public static void main(String agrs[]){
try
{
FileInputStream is;
InputStreamReader ir;
BufferedReader in;
FileOutputStream it;
OutputStreamWriter iu;
PrintWriter out;
is = new FileInputStream ("g:\c.java");
ir=new InputStreamReader(is);
in=new BufferedReader(ir);
it = new FileOutputStream ("g:\c.java");
iu=new OutputStreamWriter (it);
out = new PrintWriter(iu);
copyFile(in,out);
in.close();
is.close();
iu.close();
it.close();
}catch(FileNotFoundException e){
System.out.println("file is not found");
System.exit(-2);
}
catch(IOException e){
System.out.println("error"+e);
System.exit(-3);
}
}
private static void copyFile(BufferedReader in,PrintWriter out)
{
int length;
String s;
//byte buf[]=new byte[1000];
try{
while((s=in.readLine())!=null){
System.out.println(s);
out.println(s);
}
}catch(IOException e){
System.out.println("error"+e);
System.exit(-4);
}
}
}
public class str{
public static void main(String agrs[]){
try
{
FileInputStream is;
InputStreamReader ir;
BufferedReader in;
FileOutputStream it;
OutputStreamWriter iu;
PrintWriter out;
is = new FileInputStream ("g:\c.java");
ir=new InputStreamReader(is);
in=new BufferedReader(ir);
it = new FileOutputStream ("g:\c.java");
iu=new OutputStreamWriter (it);
out = new PrintWriter(iu);
copyFile(in,out);
in.close();
is.close();
iu.close();
it.close();
}catch(FileNotFoundException e){
System.out.println("file is not found");
System.exit(-2);
}
catch(IOException e){
System.out.println("error"+e);
System.exit(-3);
}
}
private static void copyFile(BufferedReader in,PrintWriter out)
{
int length;
String s;
//byte buf[]=new byte[1000];
try{
while((s=in.readLine())!=null){
System.out.println(s);
out.println(s);
}
}catch(IOException e){
System.out.println("error"+e);
System.exit(-4);
}
}
}
|
很简单,在你的程序里面加上一句 out.close(); 就可以了。
try{
while((s=in.readLine())!=null)
out.write(s);
out.close();
}
catch(IOException e){
System.out.println("error"+e);
System.exit(-4);
}
这样再试试!
try{
while((s=in.readLine())!=null)
out.write(s);
out.close();
}
catch(IOException e){
System.out.println("error"+e);
System.exit(-4);
}
这样再试试!