【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

posted @ 2023-05-03 09:28  逆火狂飙  阅读(42)  评论(0编辑  收藏  举报
生当作人杰 死亦为鬼雄 至今思项羽 不肯过江东