我认为这是基本的东西,但我不知道该怎么做.我为什么得到IOException never thrown in body of corresponding try statement
public static void main(String[] args)
{
File inputFile = null ;
try
{
inputFile = new File("records.txt") ;
}
catch (IOException e)
{
System.out.print("file not found!") ;
}
Run Code Online (Sandbox Code Playgroud)
它永远不会抛出IOException.创建File对象不会将其连接到磁盘上的任何内容.也就是说,没有IO.
如果您尝试从磁盘上没有相应文件的File对象读取或写入,您将获得IOExceptions.例如,如果您尝试从实际上不在磁盘上的文件中获取ComeCanonicalPath.
| 归档时间: |
|
| 查看次数: |
7239 次 |
| 最近记录: |