Re: [投稿123] System.setOut 法

看板java作者 (清兒)時間11年前 (2013/10/03 04:11), 編輯推噓1(102)
留言3則, 2人參與, 最新討論串2/2 (看更多)
個人覺得這是可以的吧 板主請問 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
應該說 java.exe 的進入點必須是 Output123 的 main()
10/03 08:57, 1F

10/03 08:58, , 2F
另外,你這招 #1IHlzfeJ 已經用了 Orz
10/03 08:58, 2F

10/03 14:38, , 3F
了解~
10/03 14:38, 3F
文章代碼(AID): #1IJ7tpfO (java)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #1IJ7tpfO (java)