FileOutputStream()里可以省略new File(“路径”)?
重定向这里看到的虽然引进了File类,但是却没有用File实例化,直接用FileOutputStream传入路径,这样可以么?System.setOut(newPrint...
重定向这里看到的
虽然引进了File类,但是却没有用File实例化,直接用FileOutputStream传入路径,这样可以么?
System.setOut( new PrintStream ( FileOutputStream("路径") ) )
如果可以,那之前IO这一章用File实例化的例子是不是都可以省略 new File("")? 展开
虽然引进了File类,但是却没有用File实例化,直接用FileOutputStream传入路径,这样可以么?
System.setOut( new PrintStream ( FileOutputStream("路径") ) )
如果可以,那之前IO这一章用File实例化的例子是不是都可以省略 new File("")? 展开
1个回答
2013-10-15
展开全部
没错
FileOutputStream
看这个的API文档,有详细说明。
Constructor Summary
FileOutputStream(File file)
Creates a file output stream to write to the file represented by
the specified File object.
FileOutputStream(File file,
boolean append)
Creates a file output stream to write to the file represented by
the specified File object.
FileOutputStream(FileDescriptor fdObj)
Creates an output file stream to write to the specified file
descriptor, which represents an existing connection to an actual
file in the file system.
FileOutputStream(String name)
Creates an output file stream to write to the file with the
specified name.
FileOutputStream(String name,
boolean append)
Creates an output file stream to write to the file with the specified
name.
FileOutputStream
看这个的API文档,有详细说明。
Constructor Summary
FileOutputStream(File file)
Creates a file output stream to write to the file represented by
the specified File object.
FileOutputStream(File file,
boolean append)
Creates a file output stream to write to the file represented by
the specified File object.
FileOutputStream(FileDescriptor fdObj)
Creates an output file stream to write to the specified file
descriptor, which represents an existing connection to an actual
file in the file system.
FileOutputStream(String name)
Creates an output file stream to write to the file with the
specified name.
FileOutputStream(String name,
boolean append)
Creates an output file stream to write to the file with the specified
name.
追问
那InputStream、FileWriter和FileReader都可以这么用?
追答
InputStream不行
具体的,还一下API文档的说明,或者在Eclipse中,new的时候,会提示
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询