日期:2014-05-20 浏览次数:20763 次
import java.io.*;
public class FileDemo {
public static void main (String[]args){
File source = new File("e:/test1/java.doc");
File target = new File("e:/test2/java.doc");
FileInputStream fis=null;
FileOutputStream fos=null;
try{
fis =new FileInputStream(source);
fos =new FileOutputStream(target);
byte[] bytes =new byte[1024];
int length;
while((length=fis.read(bytes))!=-1){
String str = new String(bytes,0,length);
System.out.println(str);
byte[] by = str.getBytes();
fos.write(by);
}
}catch(FileNotFoundException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}finally{
if(fis != null){
try{
fis.close();
}catch (IOException e){
e.printStackTrace();
}
}
if (fos != null){
try{
fos.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
}
}