读取 imp imp imp String FileContent = ""; // 文件很长的话建议使用StringBuffer try { FileInputStream fis = new FileInputStream("d:\\input.txt"); InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { FileContent += line; FileContent += "\r\n"; // 补上换行符 } } catch (Exception e) { e.printStackTrace(); } 写入 imp imp String FileContent = "文件内容"; try { FileOutputStream fos = new FileOutputStream("d:\\output.txt"); OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); osw.write(FileContent); osw.flush(); } catch (Exception e) { e.printStackTrace(); } |
|