日期:2014-05-20  浏览次数:20748 次

在Java FileWrite的那个方法可把内容续到一个文件中,而不是覆盖原有的???
我想把一个文件中所用的.txt格式的文件内容都拷到.txt文件中,现在的一个点就是找那个不覆盖原有内容的方法。  
帮帮忙。
          请大家帮我想下这个程序的基本思路??????
    谢谢!!!


------解决方案--------------------
RandomAccessFile类

File file = new File( "文件名 ");
RandomAccessFile rin = new RandomAccessFile(file);
seek(File.length()); // 移动指针到文件尾部
------解决方案--------------------
frilly(秋◆水)

说得不错
------解决方案--------------------
public void writeFile(String msg) {
try {
FileWriter fw = new FileWriter( "a.txt ",true);
PrintWriter out = new PrintWriter(fw);
out.println(msg);
out.close();
fw.close();
} catch (IOException e) {
System.out.println( "Write file error! ");
e.printStackTrace();
}
}
------解决方案--------------------
true《
------解决方案--------------------
/**
* Constructs a FileWriter object given a file name with a boolean
* indicating whether or not to append the data written.
*
* @param fileName String The system-dependent filename.
* @param append boolean if <code> true </code> , 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
*/
public FileWriter(String fileName, boolean append) throws IOException {
super(new FileOutputStream(fileName, append));
}