package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class CopyFile {
public static void main(String[] args) {
String path="f://test/";
File pathFile=new File(path);
if(!pathFile.exists()&&!pathFile.isDirectory()){
pathFile.mkdirs();
}
File inFile=new File("f://test/test.txt");
File outFile=new File("f://test/copyTest.txt");
try {
if(!inFile.exists()){
inFile.createNewFile();
}
if(!outFile.exists()){
outFile.createNewFile();
}
InputStream is=new FileInputStream(inFile);
OutputStream os=new FileOutputStream(outFile);
byte[] b=new byte[1024];
int len=0;
while((len=is.read(b))!=-1){
os.write(b, 0, len);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
java简单的文件复制
最新推荐文章于 2020-01-01 22:45:49 发布