1. 程式人生 > >JAVA 讀取檔案並更改檔案內容

JAVA 讀取檔案並更改檔案內容

 private void autoReplace(String filePath,String outPath) throws IOException{
  File file=new File(filePath);
  Long fileLength=file.length();
  byte[] fileContext=new byte[fileLength.intValue()];
  FileInputStream in=new FileInputStream(filePath);
  in.read(fileContext);
  in.close();
  String str=new String(fileContext);
  
  str=str.replace("","");
  
  PrintWriter out=new PrintWriter(outPath);
  out.write(str.toCharArray());
  out.flush();
  out.close();
 }