`
qinya06
  • 浏览: 583170 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

java file

阅读更多
追加文件尾部
public void testPrintWrite() throws Exception{
  FileWriter fw=new FileWriter("D:/text.txt",true);
  BufferedWriter bw=new BUfferWriter(fw);
  PrintWrite pw=new BufferedWriter(bw);
  pw.println("测试添加1");
 pw.println("测试添加2");
 pw.close();
 bw.close();
 fw.close();

}


----------------------------------------------
复制文件夹

public void copyFolder(String oldPath,String newPath){
 try{
    (new File(newPath)).mkdirs();//如果不存在就创建
    File a =new File(oldPath);
    String[] file=a.list();
   File temp=null;
  for(int i=0;i<file.length;i++){
   if(oldPath.endWith(File.separator)){

    temp=new File(oldFile+file[i]);
    
}else{
   temp=new File(oldFile+File.separator+file[i]);
}
if(temp.isFile()){
    FileInputStream input=new  FileInputStream(temp);
      FileOutputStream output=new  FileOutputStream(newPath+"/"+(temp.getName()).toString() );
 byte[] b=new byte[1024*5];
int len;
while((len=input.read(b))!=-1){
  output.write(b,0,len);
}
output.flush();
output.close();
input.close();


 }

if(temp.isDirectory()){
   copyFolder(oldPath+"/"+file[i],newPath+"/"+file[i]);
}
   } 
   }catch(

){

}

}

-----------------------------------
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics