Java将字符串保存到文件中
public void WriteToFile1() throws Exception {String str = "xinxi";File file = new File("file\\userConfig.xml");FileOutputStream fos = null;if (!file.exists()) {file.createNewFile();}fos = new FileOutputStream(file);byte bytes[] = new byte[1024];bytes = str.getBytes();int b = str.length();fos.write(bytes, 0, b);fos.close();}public void WriteToFile2() throws Exception {String str = "xinxi";FileWriter fw = new FileWriter("userConfig.xml", true);BufferedWriter bw = new BufferedWriter(fw);bw.newLine();bw.write(str);bw.close();fw.close();}??