第1个回答 2014-09-25
import java.io.*;
public class TestFileWriter{
public static void main(String[] args) throws Exception{
FileReader fr = null;
FileWriter fw = null;
int b = 0;
char[] cbuf = new char[18];
fr = new FileReader("E:\\java\\io\\1.txt");//1.txt保存的位置
fw = new FileWriter("E:\\java\\io\\2.txt");//2.txt保存的位置
while ((b=fr.read(cbuf,0,18))!=-1) {
fw.write(cbuf,0,18);
}
fr.close();
fw.close();
}
}
第2个回答 推荐于2016-03-04
public static void fileChannelCopy(File s, File t) {
FileInputStream fi = null;
FileOutputStream fo = null;
FileChannel in = null;
FileChannel out = null;
try {
fi = new FileInputStream(s);
fo = new FileOutputStream(t);
in = fi.getChannel();
out = fo.getChannel();
in.transferTo(0, in.size(), out);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fi.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}本回答被提问者采纳
第3个回答 2014-09-25
这个不是什么难事,去看File类,里面有方法,记着要关闭流