file not foundNotFoundException 怎么破

网络赶上1.赶上...(); dis.close();返回CKSUM;}赶上(FileNotFoundException E){e.printStackTrace(),返回-1;}赶上(IOException异常E){e.pri…|© 2015 MicrosoftJAVA提示:“未处理的异常类型 FileNotFoundException”怎么回事
JAVA提示:“未处理的异常类型 FileNotFoundException”怎么回事 50
import java.io.Fimport java.text.SimpleDateFimport java.util.*;import javax.swing.Spublic class A {&&& public static void main(String[] args)&&& {Scanner in=new Scanner(new File("F:\\s.rtf"));&& }}
不区分大小写匿名
找不到该文件,检查一下文件路径
路径没错换了路径也还是这样
就是说你的f盘下面没有这个s.rtf 文件。&&
有的啊……会不会是其他原因
不应该的啊,你跟踪看下。
第一次用eclipse不知怎么跟踪
Scanner in=new Scanner(new File("F:\\s.rtf"));&& 你在这行 行号的地方双击 就出现了个点,然后选择debug模式执行就可以了。
这个主要是要添加异常处理,防止可能发生的异常,将这句话用try-catch包起来就对了,不是说你的路径下面有没有这个文件,而是该程序在运行之前不能判断是否存在这个文件,因此要添加异常处理的代码。
抛出?这个……
把程序改成这样就可以了。import java.io.Fimport java.io.FileNotFoundEimport java.text.SimpleDateFimport java.util.*;import javax.swing.Spublic class A&{& & public static void main(String[] args)& & {& &
Scanner in=new Scanner(new File("F:\\s.rtf"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}& &}}如果这个文件是存在的,则程序正常执行,否则就通过try-catch捕获异常,通过e.printStackTrace()将异常打印出来,输出在控制台上。
in被提示The value of the local variable in is not used
catch (FileNotFoundException e)被提示执行不到的 FileNotFoundException 的 catch 块。从未从 try 语句主体抛出此异常
这个不是什么错误,它只是提示你申明的这个变量没有在后面的程序被使用到,程序以为它是多余的,是一个感叹号的标志,如果你在下面的程序中使用in,则不会有这个提示
在这段代码加上try catch监视异常!
看了一下。这里跟你说的处理方法很正确。如果你觉得麻烦可以在main方法将该异常抛出让系统来处理!但这种做法不可取,因为异常被系统含泪内吞即使出了错误程序员也不知道。
FileNotFoundException,从字面上来分析,FIle:文件。NotFound:没有找到。Exception:异常综合就是:找不到文件导致异常。谢谢
相关知识等待您来回答
编程领域专家FileNotFoundException (Java Platform SE 6)
Java™&PlatformStandard&Ed.&6
Class FileNotFoundException
java.io.FileNotFoundException
All Implemented Interfaces:
public class FileNotFoundExceptionextends
Signals that an attempt to open the file denoted by a specified pathname
has failed.
This exception will be thrown by the , , and
constructors when a file
with the specified pathname does not exist.
It will also be thrown by these
constructors if the file does exist but for some reason is inaccessible, for
example when an attempt is made to open a read-only file for writing.
&&&&&&&&&&Constructs a FileNotFoundException with
null as its error detail message.
&&&&&&&&&&Constructs a FileNotFoundException with the
specified detail message.
, , , , , , , , , ,
, , , , , , , , ,
FileNotFoundException
public FileNotFoundException()
Constructs a FileNotFoundException with
null as its error detail message.
FileNotFoundException
public FileNotFoundException(&s)
Constructs a FileNotFoundException with the
specified detail message. The string s can be
retrieved later by the
method of class java.lang.Throwable.
Parameters:s - the detail message.
Java™&PlatformStandard&Ed.&6
For further API reference and developer documentation, see . That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
© , Oracle and/or its affiliates.
All rights reserved.
Scripting on this page tracks web page traffic, but does not change the content in any way.你的位置: >
> 【android】异常:java.io.FileNotFoundException:Permission Denied解决方法
首先检查你的路径是不是对的。应该在Environment.getExternalStorageDirectory().getAbsolutePath()这个目录下写东西。 &&
如果路径是对的,那就检查是不是给你的application添加了权限。 &&
如果没有,在manifest中添加&uses-permission&android:name=&android.permission.WRITE_EXTERNAL_STORAGE&/& &&
如果上面的都有正确,但是仍然会上面的错误。 &&
请检查你的avd在创建的时候有没有设置size,如果没有设置的话就重新创建一个有size的avd。
转载请注明: &
与本文相关的文章java.io.FileNotFoundException:(拒绝访问。)
今天搞mybatis自动生成软件,报异常,如下:
xml's file path:F:\eclipse-myown\MyBatisGenerator
java.io.FileNotFoundException:
F:\eclipse-myown\MyBatisGenerator\src (拒绝访问。)
这个问题是:在windows下写入的文件必须有扩展名,否则拒绝访问!!!将配置文件修改为一下内容,正常。。。
声明:log4j等需要生成文件的,如遇到此问题,也都是因为没加扩展名,所以要加上才行。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 file lib not found 的文章

 

随机推荐