私はJavaプログラミングに不慣れで、次のコードを機能させるために最も長い間努力してきましたが、プログラムは正常に実行されますが、出力をリダイレクトしているテキストファイルに出力が表示されないようです。誰かが私を助けてくれるなら、私は非常に義務があります。以下はコード全体です。私が抱えている問題は、テキストファイルに1行しか書き込まれておらず、どの時点でもファイルに1行しかないことです。これはループとオブジェクトが毎回再初期化されることに関係していることは知っていますが、非常に基本的な間違いであることが判明するこの問題を克服する方法がわかりません。ただ、今は見えないので、よろしくお願いします。そして、すでに助けようとしたすべての人々のおかげで、あなたの提案は非常に役に立ちました。
PrintStream out;
for(int count = 0; count<list2.size(); count++)
{
String originalString = list2.get(count);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String readLine = br.readLine();
out = new PrintStream(new FileOutputStream("/Users/xyz/Desktop/metaDataFormatted.txt"));
System.out.println(readLine);
System.setOut(out);
//out.flush();
//out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error During Reading/Writing");
}
System.out.println(count+" >");
//the following line is a method from another class which produces all the output on standard out.
md.getHomePageLinks(originalString);
}