1. 程式人生 > >java怎麼把字串寫到檔案裡去

java怎麼把字串寫到檔案裡去

String s = "akjibuvuvu"; FileWriter fw = null; File f = new File("a.txt"); try { if(!f.exists()){ f.createNewFile(); } fw = new FileWriter(f); BufferedWriter out = new BufferedWriter(fw); out.write(s, 0, s.length()-1); out.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("end");