用 InputStream 與 OutputStream 來做 檔案的讀與寫 (包含檔案本身的文字編碼)
範例如下 ~
private static void readWriteFile(String absulotePathFileName,String newAbsulotePathFileName) throws IOException{
InputStream fileIn=new FileInputStream(absulotePathFileName);
Reader fileReader=new InputStreamReader(fileIn,“utf-8″);
int i=-1;
StringBuffer txtContent=new StringBuffer();
while((i=fileReader.read())!=-1){
txtContent.append((char)i);
}
fileReader.close();
fileIn.close();
File file=new File(SysConf.get(newAbsulotePathFileName);
if(!file.exists()){
file.createNewFile();
}
OutputStream fileOut=new FileOutputStream(file,true);
Writer fileWriter=new OutputStreamWriter(fileOut,“utf-8″);
fileWriter.write(txtContent.toString());
fileWriter.close();
fileOut.close();
}