File employee = new File("E:five/emplo.xml"); ファイル スタッド = 新しいファイル("E:/one/two/student.xml"); これら 2 つのファイルを 1 つのファイル オブジェクトに結合する方法
2 に答える
0
2つの標準テキストファイルをマージする場合は、ファイルライターとファイルリーダーを使用できます。
私はそれらを経験していないので、これはxml固有のものではないと思います。
(例外処理なしで)ファイルを読み取る方法は次のとおりです。
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr); // the only reason I use this is because I am used to line by line handling
String line;
while((line = br.readLine()) != null)
{
// do something with each line
}
各ファイルを文字列の配列リストに読み込んでから、次を使用して出力できます。
FileWriter fout = new FileWriter(file, toAppend);
fout.write(msg);
fout.close();
于 2012-11-12T04:42:04.470 に答える
0
String[] filenames = new String[]{ "emplo.xml", "student.xml"};
OutputStream outputStream = new BufferedOutputStream(new FileOutputStream("merged.xml");
for (String filename : filenames) {
InputStream inputStream = new BufferedInputStream(new FileInputStream(filename);
org.apache.commons.io.IOUtils.copy(inputStream, outputStream);
inputStream.close();
}
outputStream.close();<br/>
またはあなたも使用することができますSAXParser
于 2012-11-12T04:43:14.050 に答える