首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java将字符串保留到文件中

2012-09-03 
Java将字符串保存到文件中public void WriteToFile1() throws Exception {String str xinxiFile file

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();}

??

热点排行