Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一种情况,首先我在项目的所有地方都使用了 System.out.println() 现在决定代替 SOP 日志到文件中是否可以在一个地方覆盖 println() 方法并应用所有的类。简而言之,每个类都不需要改变。
我不确定这是否是您需要的,但您可以将标准输出流重定向到PrintStram另一个
PrintStram
System.setOut(new PrintStream("yourLogFile.log"));
不,System类在包java.lang中,您不能覆盖此包中的类。您需要在项目中进行重构。
System
java.lang