文件复制
public void fuzhi(File file, String path){
FileInputStream fis = null;
FileOutputStream fos = null;
try {
//读取文件 // 创建一个输入流对象
fis= new FileInputStream(file);
//创建一个输出流对象
File newFiel = new File(file.getName());
fos = new FileOutputStream(newFiel);
byte[] b = new byte[1024];//会默认存储1024位
int count = fis.read(b);
while(count!=-1){
// byte temp = b[0];//这三行代表加密,如果是记事本就不行,只是用来交换位置,记事本交换位置并 不会有太大的变化
// b[0]= b[1];
// b[1] = temp;
fos.write(b,0,count);
fos.flush();
count = fis.read(b);
}
} 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();
}
}
}
}<br />真正的流程也就那几行,读取文件,写入文件就可以了<br />字符型文件流:<br /> FileReader:<br /> 常用的方法跟字节流是一样的<br /> read()<br /> read(char[])<br /> FileWriter:<br /> 构造方法 :带file参数,带file,boolean 参数<br /> 带String参数, 带String boolean参数<br />用法:<br /> write(int)<br /> write(char)<br /> write(String)<br /> close flush