日期:2014-05-20 浏览次数:20945 次
File file1 = new File("D:/testfile1.xml");
File file2 = new File("D:/testfile2.xml");
OutputStream os =null;
InputStream is =null;
try {
os = new FileOutputStream(file1,true);
is = new FileInputStream(file2);
byte b[]=new byte[is.available()];
is.read(b);
os.write(b);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
os.close();
os=null;
is.close();
is=null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
------解决方案--------------------
写第一个文件就可以了。读出第二个文件,然后把相应内容加到第一个文件的里面,然后执行对第一个文件的写操作。
------解决方案--------------------
用dom4j比较容易实现。