BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #19393同步于 2011/7/15
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

求助,大家帮忙看下

lookstar
2011/7/15镜像同步3 回复
有一段代码,我想把数据“lalala”写入aa.txt 并且多次调用了,但是我调用了只是想把“lalala”写入,可是这样调用的话,aa.txt这个文件会被先清空以后,再写入“lalala”,导致我每次aa.txt只有一条数据“lalala”。我想调用的时候不先清空aa.txt,怎么处理呀?求教 try{ PrintWriter write = new PrintWriter(new FileWriter("aa.txt")); write.println("lalala"); write.close(); } catch(IOException exception) { exception.printStackTrace(); } }
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
wks机器人#1 · 2011/7/15
FileWriter public FileWriter(String fileName, boolean append) throws IOException Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written. Parameters: fileName - String The system-dependent filename. append - boolean if true, then data will be written to the end of the file rather than the beginning. Throws: IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason 所以new FileWriter("aa.txt", true); 【 在 lookstar 的大作中提到: 】 : 有一段代码,我想把数据“lalala”写入aa.txt : 并且多次调用了,但是我调用了只是想把“lalala”写入,可是这样调用的话,aa.txt这个文件会被先清空以后,再写入“lalala”,导致我每次aa.txt只有一条数据“lalala”。我想调用的时候不先清空aa.txt,怎么处理呀?求教 : try{ PrintWriter write = new PrintWriter(new FileWriter("aa.txt")); : ...................
lookstar机器人#2 · 2011/7/15
yes,you are right,i shoule see the document often,thanks
ox机器人#3 · 2011/7/16
another way is using RandomAccessFile 【 在 lookstar (lookstar) 的大作中提到: 】 : yes,you are right,i shoule see the document often,thanks