UTF-16 でエンコードされたファイルの SequenceStream を作成しようとしました。
public class sequenceStream {
public static void main(String[] args) {
try {
File f1 = new File("C:\\Temp\\sequence1.txt");
File f2= new File("C:\\Temp\\sequence2.txt");
File f3= new File("C:\\Temp\\sequence3.txt");
InputStream is = getSequencedInputStream(f1,f2,f3);
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-16"));
String line;
int count=0;
while((line = br.readLine()) !=null){
count++;
System.out.println(count + " : " + line);
}
br.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
private static InputStream getSequencedInputStream(File ... files) {
Vector v = new Vector(files.length);
for (int i=0; i<files.length;i++){
if(files[i].exists()){
try {
v.add(new FileInputStream(files[i]));
} catch (FileNotFoundException e) {
}
}
}
return new SequenceInputStream(v.elements());
}
}
これを実行すると、出力としてこれが得られます:
1 : first file, first line
2 : first file, second line?second file, first line
3 : second file, second line?third file, first line
4 : third file, second line
私がそれを実行すると、ファイルが1つだけで正常に動作します:
InputStream is = getSequencedInputStream(f1);
出力:
1 : first file, first line
2 : first file, second line
クエスチョンマークはどこから?どうすればこれを処理できますか?