try {
//读取文件数据到缓冲区
FileInputStream fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr);
//写入新文件
File newfile = new File("newtest.txt"); FileOutputStream fos = new FileOutputStream(newfile); OutputStreamWriter osw = new OutputStreamWriter(fos); BufferedWriter bw = new BufferedWriter(osw); String line; while ((line = br.readLine()) != null) { bw.write(line); bw.newLine();//分行 } bw.close(); osw.close(); fos.close(); br.close(); isr.close(); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } System.err.println("exists"); } }