輸入輸出文件

String path = "D:\\bak";
String outPath = "D:\\";
FileWriter fw = null;
OutputStreamWriter outputStream = null;
FileOutputStream fileOutputStream = null;
BufferedReader reader = null;

File file = new File(path);
File[] files = file.listFiles();

int line = 0;
for (int i = 0; i < files.length; i++) {
String filePath = files[i].getPath();
String fileName = files[i].getName();

// reader = new BufferedReader(new FileReader(new File(filePath)));


FileInputStream fr = new FileInputStream(filePath);
InputStreamReader is = new InputStreamReader(fr, "UTF-8");
reader = new BufferedReader(is);

String tempString = "";
String str = "";

while ((tempString = reader.readLine()) != null) {
if (!"".equals(tempString) && tempString.indexOf("hhhj") == -1) {
// String[] strs = tempString.split("\\|#\\$\\|");
// for (int j = 0; j < strs.length; j++) {
// System.out.println(strs[j]);
// }
fileOutputStream = new FileOutputStream(outPath+fileName,true);
outputStream = new OutputStreamWriter(fileOutputStream, "UTF-8");


outputStream.write(tempString);
outputStream.write("\r\n");
outputStream.flush();
}
line++;
}



}
發佈了171 篇原創文章 · 獲贊 4 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章