作者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
1F:推 PsMonkey:囧... 到最後执行 Output.class 吗? 这样只能有参加奖喔 09/28 13:23
2F:→ Schelfaniel:用JVM执行Output.class不过里面有执行Output123.class 09/28 13:29
3F:推 cuteclare:帮补 10/03 04:07