Re: [投稿123] System.setOut 法
個人覺得這是可以的吧
板主請問 java.lang.ClassLoader 這種方法可不可以用
如果可以
原po的意思應該是這樣
Loader123.java
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
public class Loader123 extends ClassLoader {
public 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 Loader123(ClassLoader parent) {
super(parent);
java.lang.System.setOut(new Loader123.MyOutputStream(java.lang.System.out));
}
}
java -Djava.system.class.loader=Loader123 Output123
如果能用 Java.lang.ClassLoader 其實應該會有很多答案
※ 引述《Schelfaniel (Schelfaniel)》之銘言:
: 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: 114.25.239.245
※ 編輯: cuteclare 來自: 114.25.239.245 (10/03 04:15)
推
10/03 08:57, , 1F
10/03 08:57, 1F
→
10/03 08:58, , 2F
10/03 08:58, 2F
→
10/03 14:38, , 3F
10/03 14:38, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
java 近期熱門文章
PTT數位生活區 即時熱門文章