输入输出文件

来源:互联网 发布:化妆品成分查询软件 编辑:程序博客网 时间:2024/05/01 11:13
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++;
}



}
原创粉丝点击