public boolean createNewFile () 解释
2013-01-19 18:31
495 查看
boolean java.io.File.createNewFile() throws IOException
public boolean createNewFile ()
Since: API Level 1
Creates a new, empty file on the file system according to the path information stored in this file. This method returns true if it creates a file, false if the file already existed. Note that it returns false even if the file is not a file (because it's
a directory, say).
在文件系统中根据保存在文件中的路径信息,创建一个新的空文件。如果创建成功就会返回true,如果文件存在返回false。注意:如果他已经存在但不是文件,可能是目录也会返回false。
This method is not generally useful. For creating temporary files, use createTempFile(String, String) instead. For reading/writing files, use FileInputStream, FileOutputStream, or RandomAccessFile, all of which can create files.
这个方法不是很常用。创建临时文件通常使用createTempFile(String,String)替代。创建读/写文件使用FileInputStream,FileOutputStream,或者RandmomAccessFile,他们都可以创建文件。
Note that this method does not throw IOException if the file already exists, even if it's not a regular file. Callers should always check the return value, and may additionally want to call isFile().
注意,这个方法如果遇到文件存在不会抛出异常,及时是一个不规则的文件。调用者应该总是检查返回值,或者需要额外的调用isFile()来判断。
Returns
true if the file has been created, false if it already exists.
Throws
IOException if it's not possible to create the file.
如果不能创建文件就会抛出异常。
例如:
File file = new File(SDPATH + fileName);
file.createNewFile();
public boolean createNewFile ()
Since: API Level 1
Creates a new, empty file on the file system according to the path information stored in this file. This method returns true if it creates a file, false if the file already existed. Note that it returns false even if the file is not a file (because it's
a directory, say).
在文件系统中根据保存在文件中的路径信息,创建一个新的空文件。如果创建成功就会返回true,如果文件存在返回false。注意:如果他已经存在但不是文件,可能是目录也会返回false。
This method is not generally useful. For creating temporary files, use createTempFile(String, String) instead. For reading/writing files, use FileInputStream, FileOutputStream, or RandomAccessFile, all of which can create files.
这个方法不是很常用。创建临时文件通常使用createTempFile(String,String)替代。创建读/写文件使用FileInputStream,FileOutputStream,或者RandmomAccessFile,他们都可以创建文件。
Note that this method does not throw IOException if the file already exists, even if it's not a regular file. Callers should always check the return value, and may additionally want to call isFile().
注意,这个方法如果遇到文件存在不会抛出异常,及时是一个不规则的文件。调用者应该总是检查返回值,或者需要额外的调用isFile()来判断。
Returns
true if the file has been created, false if it already exists.
Throws
IOException if it's not possible to create the file.
如果不能创建文件就会抛出异常。
例如:
File file = new File(SDPATH + fileName);
file.createNewFile();
相关文章推荐
- public static File createNewFile(String filePath)
- Java 中File类的createNewFile()与createTempFile(), delete和deleteOnExit区别
- File类的createNewFile()与createTempFile()的区别
- Android mkdirs或mkdir一直返回false(createNewFile也失败)
- File FilecreateNewFile()和createTempFile()的区别
- public FileOutputStream (File file) 的解释
- log4j create a new log file every day
- 记录一次File.createNewFile()报错的解决方法
- android file.createnewfile ioexception
- Android File.createNewFile失败; Android6.0以上需要用户给权限
- #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif 语句解释
- boolean java.io.File.mkdir()和boolean java.io.File.exists()解释
- createNewFile创建空文件夹与createTempFile创建临时文件夹
- 关于Android file.createNewFile() 方法出现的问题总结
- Fle.createNewFile() 和 Fle.createTempFile() 比较和区别
- File中createNewFile()和createTempFile()区别
- java io中CreateNewFile()和createTempFile()
- android file.createnewfile ioexception
- Android中使用file.createNewFile()无法创建文件的问题(例如保存拍照的图片到本地)
- 怎么创建文件夹呢?mkdir、mkdirs、createNewFile