dexline4
dexline4
2011-09-18 21:02

一个简单的读取文件为啥搞成了死循环?

  • it技术
  • 互联网问答
  • IT行业问题
  • 编程语言问答
  • 计算机技术

import java.io.*;

public class TestMove{

private static File f1=null;

private static File f2=null;

private static FileInputStream fis=null;

private static FileOutputStream fos=null;

public static void main(String []args){

new TestMove("D:\\f1\\file1.txt","D:\\f2\\file2.txt").startCopy();

}

public TestMove(String f1,String f2){

try{

this.f1=new File(f1);

this.f2=new File(f2);

fis=new FileInputStream(this.f1);

fos=new FileOutputStream(this.f2);

}catch(IOException e){

System.out.print("wrong!");

}

}

public void startCopy(){

System.out.println(f1.length());

try{

for(int take=fis.read();take!=-1;){

System.out.print(""+take);

System.out.print(""+(char)take);

//fos.write(take);

}

fis.close();

//fos.close();

}catch(IOException e){

System.out.println("Something is wrong!");

}

}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐