下面代码中tempsrctxt 是已知的一个excel文件,我要新建一个文件tempname, 在新建一个POIFSFileSystem对象,把ldFile放里面报系统找不到该文件。String tempsrctxt = this.getsrcFileTxt().getText();
String tempname = tempsrctxt.substring(0,tempsrctxt.lastIndexOf("."))+"报错信息.xls";
File ldFile = new File(tempname);//新建文件
POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream(ldFile))//报系统找不到该文件这个问题怎么处理,谢谢了
String tempname = tempsrctxt.substring(0,tempsrctxt.lastIndexOf("."))+"报错信息.xls";
File ldFile = new File(tempname);//新建文件
POIFSFileSystem fs =new POIFSFileSystem(new FileInputStream(ldFile))//报系统找不到该文件这个问题怎么处理,谢谢了
并没有新建文件。
ldFile.createNewFile() //这个方法才会新建文件
不是新建文件。
public File(String pathname)通过将给定路径名字符串转换为抽象路径名来创建一个新 File 实例。如果给定字符串是空字符串,那么结果是空抽象路径名。 参数:
pathname - 路径名字符串
抛出:
NullPointerException - 如果 pathname 参数为 null
createNewFile
public boolean createNewFile()
throws IOException当且仅当不存在具有此抽象路径名指定名称的文件时,不可分地创建一个新的空文件。检查文件是否存在,若不存在则创建该文件,这是单个操作,对于其他所有可能影响该文件的文件系统活动来说,该操作是不可分的。
注:此方法不应该 用于文件锁定,因为所得协议可能无法可靠地工作。应该使用 FileLock 机制替代。
返回:
如果指定的文件不存在并成功地创建,则返回 true;如果指定的文件已经存在,则返回 false
抛出:
IOException - 如果发生 I/O 错误
SecurityException - 如果存在安全管理器,且其 SecurityManager.checkWrite(java.lang.String) 方法拒绝对文件进行写访问
从以下版本开始:
1.2