java 实现文件夹的拷贝实例代码
这里就直接上代码,废话不多说,很简单很实用。
实例代码:
import java.io.file;
import java.io.fileinputstream;
import java.io.filenotfoundexception;
import java.io.fileoutputstream;
public class copyfile {
public static void copy(string sourcefile , string targetfile) throws exception{
fileinputstream in = null;
fileoutputstream out = null;
try{
in = new fileinputstream(new file(sourcefile));
out = new fileoutputstream(new file(targetfile));
int c;
while ((c = in.read()) != -1 ){
out.write(c);
}
}
finally{
if (in != null){
in.close();
}
if(out != null){
out.close();
}
}
}
public static void main(string[] agrs) throws exception{
string filedir = "./tupu0";
string targetdir = "./movielist/";
file directory = new file(filedir);
file[] filelist = directory.listfiles();
for(int i=0; i
string sourcefile = "./tupu0/" + filelist[i].getname() + "/" + filelist[i].getname() +".txt";
string targetfile = targetdir + filelist[i].getname();
system.out.println(filelist[i].getname());
copy(sourcefile, targetfile);
}
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
希望与广大网友互动??
点此进行留言吧!