没有System.out怎么办,在控制台上打印? [英] What to do without System.out, to print on console?
问题描述
我一直遇到最近在接受采访时被问到的问题。问题表示为 - >假设您无法访问Jdk API中的System类,也无法使用ECHO,您在JRE 5环境中,如何在控制台上打印任何内容?问题真正开始于 - 为什么Java给了我们PrintStream对象System.out ??为什么它是最终的?没有任何其他方法可以在控制台上打印任何东西。??
I have been stuck with a problem that was asked recently at an interview. The problem is stated as--> Suppose you don't have access to System class in Jdk API, Also you cannot use ECHO, you are in JRE 5 environment, how will you print anything on console?? The question really started with -- Why has Java given us the PrintStream object System.out ??And why is it final?? Isn't there any other way to print anything on console.??
推荐答案
如果你想要绕过System对象。 System.out做了很多额外的事情(例如处理unicode),所以如果你真的只想要原始输出和性能,你实际上甚至可能绕过它。
You could bypass the System object if you want to. System.out does a lot of extra stuff (handling unicode, for instance), so if you really want just the raw output and performance, you actually probably even should bypass it.
import java.io.*;
public class PrintOutTest {
public static void main(String args[]) throws IOException {
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(FileDescriptor.out), "ASCII"), 512);
out.write("test string");
out.write('\n');
out.flush();
}
}
这已在这里。
这篇关于没有System.out怎么办,在控制台上打印?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!