FileOutputStream public FileOutputStream(String name) throws FileNotFoundExceptionCreates an output file stream to write to the file with the specified name. A new FileDescriptor object is created to represent this file connection. First, if there is a security manager, its checkWrite method is called with name as its argument. If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown. Parameters: name - the system-dependent filename Throws: FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason SecurityException - if a security manager exists and its checkWrite method denies write access to the file. See Also: SecurityManager.checkWrite(java.lang.String)
这是FileOutputStream的一个构造方法,name代表文件的名字,不是目录,如果系统发现这个name代表一个目录名而不是文件名,或者文件不存在但也不能被新建又或者文件存在但不能被打开等原因,就会抛FileNotFoundException(如果不存在该文件,系统会尝试新建的)
FileOutputStream out=new FileOutputStream("sourcesum.txt")
不存在格式问题,如果是文本文件的话,可以用记事本来打开看看
如果是二进制文件的话可以用Ultraedit来看看
FileOutputStream out=new FileOutputStream(new File("out.txt"));
public FileOutputStream(String name)
throws FileNotFoundExceptionCreates an output file stream to write to the file with the specified name. A new FileDescriptor object is created to represent this file connection.
First, if there is a security manager, its checkWrite method is called with name as its argument. If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
Parameters:
name - the system-dependent filename
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
SecurityException - if a security manager exists and its checkWrite method denies write access to the file.
See Also:
SecurityManager.checkWrite(java.lang.String)