作者Schelfaniel (Schelfaniel)
看板java
標題[投稿123] System.setOut 法
時間Sat Sep 28 13:22:31 2013
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
class MyOutputStream extends PrintStream {
MyOutputStream(OutputStream out) {
super(out);
}
public void write(byte[] b, int off, int len)
{
// 這邊應該有更好的寫法,不過我先用比較笨的 :Q
byte[] new_b = new byte[b.length];
for (int i = off; i < len; i++)
if (b[i] < 10) // 避免轉換 \r\n
new_b[i] = (byte)(b[i] + 48);
else
new_b[i] = b[i];
super.write(new_b, off, len);
}
}
public class Output {
public static void main(String[] args) {
System.setOut(new MyOutputStream(System.out));
Output123.main(null);
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.251.145.119
推 PsMonkey:囧... 到最後執行 Output.class 嗎? 這樣只能有參加獎喔 09/28 13:23
→ Schelfaniel:用JVM執行Output.class不過裡面有執行Output123.class 09/28 13:29
推 cuteclare:幫補 10/03 04:07