タイトルによれば、1行(System.out.print
)を配列/ arrayListに格納したいとします。 これまではByteArrayOutputStream
を試しましたが、すべてを1つのオブジェクトに追加するだけです。必要に応じてコードのスニペットを投稿して嬉しいです。 noobの問題のため申し訳ありませんコンソールの出力を1行に格納する
編集コード:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
PrintStream old = System.out;
String[] str= new String[10];
System.setOut(ps);
for(int x=0;x<str.length;x++){
ps.println("Test: "+x);
str[x] = baos.toString();
}
System.out.flush();
System.setOut(old);
for(int x=0;x<str.length;x++){
System.out.println(str[x]);
}
出力:
str[0] = "Test: 0"
str[1] = "Test: 1"
str[2] = "Test: 2"
str[3] = "Test: 3"
str[4] = "Test: 4"
str[5] = "Test: 5"
str[6] = "Test: 6"
str[7] = "Test: 7"
str[8] = "Test: 8"
str[9] = "Test: 9"
I:私はstr
配列にしたいと思い何
Test: 0
Test: 0
Test: 1
Test: 0
Test: 1
Test: 2
Test: 0
Test: 1
Test: 2
Test: 3
Test: 0
Test: 1
Test: 2
Test: 3
Test: 4
Test: 0
Test: 1
Test: 2
Test: 3
Test: 4
Test: 5
Test: 0
Test: 1
Test: 2
Test: 3
Test: 4
Test: 5
Test: 6
Test: 0
Test: 1
Test: 2
Test: 3
Test: 4
Test: 5
Test: 6
Test: 7
Test: 0
Test: 1
Test: 2
Test: 3
Test: 4
Test: 5
Test: 6
Test: 7
Test: 8
Test: 0
Test: 1
Test: 2
Test: 3
Test: 4
Test: 5
Test: 6
Test: 7
Test: 8
Test: 9
はこのようなものですByteArrayOutputStream
ではなく値を削除するようなものも探しました運
試したコードを追加してください。あなたの入力は何ですか?どのような出力をしたいですか? – thegauravmahawar
出力をファイルにリダイレクト –