
关于JAVA中打印流的一个问题
PrintStreamps=newPrintStream(newFileOutputStream(newFile("d:"+File.separator+"test.tx...
PrintStream ps=new PrintStream(new FileOutputStream(new File("d:"+File.separator+"test.txt")))
ps.print("hello")
ps是printstream的对象调用了print方法向文件中写入了hello
System.out同样是printstream的对象可如果调用print方法即System.out.print("hello")却是在屏幕上打印hello这是为什么 展开
ps.print("hello")
ps是printstream的对象调用了print方法向文件中写入了hello
System.out同样是printstream的对象可如果调用print方法即System.out.print("hello")却是在屏幕上打印hello这是为什么 展开
展开全部
流的指向不一样啊,你自己用的是文件流当然打印到文件里,System的是控制台
追问
是不是流指向不同就调用了print方法的不同部分
追答
print是向流写入数据,就像你往水管里倒水,水管的另一段指着哪里,水当然就流到不同的地方了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询