【Java/文本文件存取】文本文件存取示例(UTF-8)
【将信息存入文件】
FileOutputStream writerStream = new FileOutputStream("config.ini"); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(writerStream, "UTF-8")); writer.write("文件内容"); writer.close();
【从文件取出信息】
File file=new File("config.ini"); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } br.close();
END