草庐IT

fileNotFoundException

全部标签

java - 在java中重新抛出异常

我有一个关于在Java中重新抛出异常的非常简单的问题。这是代码片段:publicstaticvoidmain(String[]args)throwsFileNotFoundException{try{FileReaderreader=newFileReader("java.pdf");}catch(FileNotFoundExceptionex){throwex;}}publicstaticvoidmain(String[]args)throwsFileNotFoundException{FileReaderreader=newFileReader("java.pdf");}为什么我们

java - 错误 : unreported exception FileNotFoundException; must be caught or declared to be thrown

这个问题在这里已经有了答案:Whatdoes"error:unreportedexception;mustbecaughtordeclaredtobethrown"meanandhowdoIfixit?(1个回答)关闭5个月前。我正在尝试创建一个将字符串输出到文本文件的简单程序。使用我在此处找到的代码,我将以下代码放在一起:importjava.io.*;publicclassTesting{publicstaticvoidmain(String[]args){Filefile=newFile("file.txt");file.getParentFile().mkdirs();Prin

java - FileNotFoundException 与 NoSuchFileException

我注意到另一个指示文件不存在的Java异常-NoSuchFileException。我的任务是重构某个api,它从不同的方法中抛出这两个,我只想使用一个。我应该将NoSuchFileException映射到文件到FileNotFoundException吗?我应该使用NoSuchFileException而不是FileNotFoudnException因为它更具体吗?编辑:更新了问题。我在发布此问题之前阅读了文档并了解了基本区别。我希望在这种情况下获得更多信息和指导,因为按类型进行异常处理对于服务api的客户端很重要,我希望避免需要对两种异常类型进行检查的情况。

java - 在 Java 中捕获 block 变量警告

作为标准做法,我尝试让我的代码在没有错误和警告的情况下进行编译。不过,有一个烦人的警告,我知道如何在.NET中处理,但不知道如何在Java中处理。假设我有这样的代码块:try{FileInputStreamin=newFileInputStream(filename);returnnewScanner(in).useDelimiter("\\A").next();}catch(FileNotFoundExceptionex){LOG.log(Level.SEVERE,"Unabletoloadfile:{0}",filename);returnnull;}我收到一条警告,指出未使用变量

java.io.FileNotFoundException,找不到文件

我只想逐行读取文件。这本来很简单,但我就是做对了!StringfileName="C:/Users/Diogo/Desktop/Krs_Grafo/Graph.txt";FileReaderfile=newFileReader(fileName);BufferedReaderinputStream=newBufferedReader(file);System.out.println(inputStream.readLine());我一直收到错误:Exceptioninthread"main"java.io.FileNotFoundException:C:\Users\Diogo\Des

java - Wildfly 无法部署应用程序(FileNotFoundException - 访问被拒绝)

Wildfly8.2.0.FinalJDK8更新60EclipseMars更新1JBoss工具4.3.0.FinalWindows10最近我升级了以下东西:从Windows7到Windows10从EclipseMars到EclipseMarsUpdate1从JBossTools4.3.0.Beta1到JBossTools4.3.0.Final现在,当我尝试在Eclipse中部署我的应用程序时,它不再起作用(有时它能起作用,但大多数时候它不起作用)。升级前一切正常,但现在我在部署应用程序时得到了这个堆栈跟踪(你在下面看到“Acessonegado”意味着“访问被拒绝”):13:18:12

java - src/main/resources 中的 FileNotFoundException

我在我的maven项目中放置了一个文件在src/main/resources下文件名只是temp.txt。当我尝试打开文件时:BufferedReaderbr=newBufferedReader(newFileReader(newFile("./temp.txt")));我得到一个错误:Exceptioninthread"main"java.io.FileNotFoundException:\temp.txtsrc/main/resources下的所有文件都放在根目录下maven下的类路径。那么为什么程序不能在这里找到文件呢? 最佳答案

c# - ApplicationSettingsBase 中的 FileNotFoundException

在调试应用程序时,如果在VisualStudio中启用了异常中断,我总是会收到以下错误。这真的很烦我,因为我们使用异常中断。有趣的是,当我继续时它仍然有效(StringCollection已加载)。信息是:Couldnotloadfileorassembly'System.XmlSerializers,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089'oroneofitsdependencies.Thesystemcannotfindthefilespecified.这是导致异常的代码(设计者生成的)[glo

c# - ApplicationSettingsBase 中的 FileNotFoundException

在调试应用程序时,如果在VisualStudio中启用了异常中断,我总是会收到以下错误。这真的很烦我,因为我们使用异常中断。有趣的是,当我继续时它仍然有效(StringCollection已加载)。信息是:Couldnotloadfileorassembly'System.XmlSerializers,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089'oroneofitsdependencies.Thesystemcannotfindthefilespecified.这是导致异常的代码(设计者生成的)[glo

c# - Windows 10 更新后 System.DirectoryServices.AccountManagement.PrincipalContext 损坏

在过去的几年里,我一直在使用这个小功能来验证用户凭据,没有任何问题。createPrincipalContext方法返回一个带有ContextType.Machine和机器名称的PrincipalContext。publicstaticboolValidateCredentials(stringusername,stringpassword,stringdomain=null){try{using(varprincipalContext=createPrincipalContext(username,domain)){username=GetLoginInfo(username).Us