java 文件读取写入
1.文件写入
try { FileWriter fw = new FileWriter("aaaaa", true); String[] list={"Hello,world","Are you okay?","Do you know this one?"}; for (String item : list) { fw.write(item +'\n'); } fw.close(); }catch (IOException exception){ System.out.println(exception); }
2.文件读取
try { InputStreamReader read = new InputStreamReader( new FileInputStream("D:\\antonio\\example"), StandardCharsets.UTF_8); BufferedReader bufferedReader = new BufferedReader(read); String line = null; while ((line = bufferedReader.readLine()) != null) { System.out.println(line); } bufferedReader.close(); read.close(); }catch (IOException exception){ System.out.println(exception); }