Tag: filenotfoundexception

HttpURLConnection java.io.FileNotFoundException

我目前使用下面的代码。 我是这个新function,所以它可能只是简单的东西,但我似乎无法得到这个与我的服务器一起工作。 下面的代码很好,如果我连接似乎是Apache服务器,但是当我尝试连接到我的.Net服务器,它会引发错误。 我猜这是一个标题的要求,但似乎无论在哪里尝试,都无法取得成功。 public String Download(String Url) { String filepath=null; try { //set the download URL, a url that points to a file on the internet //this is the file to be downloaded URL url = new URL(Url); //create the new connection HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); //set up some things on the connection […]

Python的“open()”为“文件未find”抛出不同的错误 – 如何处理这两个exception?

我有一个脚本,提示用户键入要打开的文件的文件名,如果该文件不存在于当前目录中,则会再次提示用户。 这是简短的版本: file = input("Type filename: ") … try: fileContent = open(filename, "r") … except FileNotFoundError: … 当我在Python 3.3x的MacOS X上testing我的脚本时,当我input错误的文件名(它在“expect”下执行套件)时,它工作得很好。 但是,当我想在Python 3.2x的Windows计算机上运行我的代码时,出现“FileNotFoundError”未定义的错误。 所以,Windows上的Python 3.2认为“FileNotFoundError”是一个variables,程序退出时出现错误。 我发现如果input文件名无效的话,Windows 3.2上的Python 3.2会抛出一个“IOError”。 我在Python 2.7的Linux机器上testing了它,它也是一个IOError。 我的问题是,现在的代码与 except "FileNotFoundError": 不会在Windows的Python 3.2上运行,但如果我改变它 except "IOError": 它不会在我的Mac上工作了。 我怎么能解决它? 我能想到的唯一方法就是使用except我通常不想要的东西。

HttpURLConnection冰淇淋三明治FileNotFoundException

我有一个Android应用程序,可以在Android 2.x和3.x下正常工作,但在Android 4.x上运行时会失败。 问题出在这部分代码中: URL url = new URL("http://blahblah.blah/somedata.xml"); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.setDoOutput(true); urlConnection.connect(); InputStream inputStream = urlConnection.getInputStream(); 当应用程序在Android 4.x上运行时, getInputStream()调用将导致FileNotFoundException 。 当相同的二进制文件在早期版本的Android上运行时,它会成功。 这些url在网页浏览器中也可以正常工作,并且可以使用curl 。 显然,有关HttpURLConnection内容在ICS中已经发生了变化。 有没有人知道发生了什么变化,以及/或者修补程序可能是什么?

如何检查Windowsapp store中是否存在文件?

是否有任何其他方式来检查文件是否存在于Windowsapp store? try { var file = await ApplicationData.Current.LocalFolder.GetFileAsync("Test.xml"); //no exception means file exists } catch (FileNotFoundException ex) { //find out through exception }

Java小程序无法在Safari 7下打开文件(Mac OS X 10.9)

我们有一个使用Java小应用程序来处理本地磁盘上的文件的Web应用程序。 我们已经开发了相当长的一段时间,而且我们已经知道所有types的applet都可能具有现代操作系统和浏览器以及最新的Java版本和新的安全限制。 昨天,苹果公司推出了全新的Mac OS 10.9 Mavericks(7.0)。 我在Safari 7 / Mac OS X 10.9下testing了我们的networking应用程序,发现Safari 7(可能?)阻止从Java applet访问本地文件。 尽pipe小应用程序(有效的Thawte证书签名,并满足Java 7u45特有的所有安全性要求)以完全访问本地文件系统的不受限制的模式运行(Java安全提示表示),但试图访问本地文件时,它会捕获fileNotFoundException : java.io.FileNotFoundException: /Users/yury/Pictures/Paris 2012/L1050258.jpg (Operation not permitted) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:146) at com.trackntag.ava(Unknown Source) 当从applet打开Java文件打开对话框时,它不显示文件,文件夹select器中的文件夹没有任何图标(通常应该有它们)。 当您回溯到根文件夹时,您可以看到顶层文件夹(bin,cores,dev,home等),但无法浏览它们。 该applet可以在同一台机器(Java 7u45,Mac OS X 10.9)上使用最新的Firefox 24 for Mac访问本地文件。 与Safari 6和Mac OS X 10.8.5一样,更不用说在各种configuration下的Linux和Windows机器了:访问本地文件没有问题。 综上所述,我必须得出结论,我们遇到了Safari 7特有的问题。 你对这个问题有什么想法吗? 任何想法,不胜感激。 干杯,尤里 编辑(答案):在Safari 7中有一个新的安全设置:安全/不安全模式(我认为它只适用于Java插件)。 您可以允许Java插件以不安全模式工作,适用于单个网站或所有网站。 […]

FileNotFoundException从HttpURLConnection获取InputStream对象

我想发送一个URL使用HttpURLConnection(在Java中使用cUrl)发送请求。 请求的内容是xml,在结束点,应用程序处理xml并将logging存储到数据库,然后以xmlstring的forms发回响应。 该应用程序在本地托pipe在apache-tomcat上。 当我从terminal执行这个代码时,一行被按预期添加到数据库。 但从连接中获取InputStream时会引发exception java.io.FileNotFoundException: http://localhost:8080/myapp/service/generate at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1401) at org.kodeplay.helloworld.HttpCurl.main(HttpCurl.java:30) 这是代码 public class HttpCurl { public static void main(String [] args) { HttpURLConnection con; try { con = (HttpURLConnection) new URL("http://localhost:8080/myapp/service/generate").openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); con.setDoInput(true); File xmlFile = new File("test.xml"); String xml = ReadWriteTextFile.getContents(xmlFile); con.getOutputStream().write(xml.getBytes("UTF-8")); InputStream response = con.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(response)); […]

java.io.FileNotFoundException:(访问被拒绝)

我试图读取文件夹内的文件,但是当我运行该程序时,它会引发此exception。 我也尝试了一些其他的文件夹。 它引发同样的exception。 Exception in thread "main" java.io.FileNotFoundException: C:\backup (Access is denied) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source)

java.io.FileNotFoundException:该文件不能作为文件描述符打开; 它可能是压缩的

我正在编程从android的音板。 问题是,一些声音的作品,有些不工作。 这里是我得到的声音不起作用的追溯 05-31 13:23:04.227 18440 18603 W System.err: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed 05-31 13:23:04.227 18440 18603 W System.err: at android.content.res.AssetManager.openAssetFd(Native Method) 05-31 13:23:04.227 18440 18603 W System.err: at android.content.res.AssetManager.openFd(AssetManager.java:331) 05-31 13:23:04.227 18440 18603 W System.err: at com.phonegap.AudioPlayer.startPlaying(AudioPlayer.java:201) 05-31 13:23:04.227 18440 18603 W System.err: […]

开放失败:EACCES(权限被拒绝)

我在某些设备上访问存储时出现了一个非常奇怪的问题。 该应用程序适用于我的testing设备(Nexus 4和7,三星GS5)。 我的所有设备运行Android 4.4.2。 但是我收到很多来自用户的电子邮件,说应用程序不能写入存储器(既不是内部存储器也不是SD卡)。 从用户反馈收到的日志文件中,我可以看到问题是以下代码: try { if (fStream == null) { fStream = new FileOutputStream(filename, true); } fStream.write(data, 0, bytes); return; } catch (IOException ex) { ex.printStackTrace(); } 它会引发exceptionfStream = new FileOutputStream(filename,true); 创buildFileOutputStream时。 堆栈日志是: W/System.err( 8147): Caused by: java.io.FileNotFoundException: /storage/emulated/0/my_folder/test_file_name.png: open failed: EACCES (Permission denied) w/System.err( 8147): at libcore.io.IoBridge.open(IoBridge.java:409) W/System.err( 8147): at […]

新的Java文件()说FileNotFoundException但文件存在

我有一个CS类的任务,它说要读取一个文件有几个testing成绩,并要求我总结和平均他们。 虽然总结和平均很容易,我有文件阅读的问题。 导师说使用这个语法 Scanner scores=new Scanner(new File("scores.dat")); 但是,这会引发FileNotFoundExceptionexception,但是我一遍又一遍地检查文件是否存在于当前文件夹中,之后我发现它必须对权限进行操作。 我改变了读写权限给大家,但是仍然无法正常工作,而且仍然一直在抛出错误。 有没有人有任何想法,为什么这可能发生? 编辑:它实际上是指向一个目录,但是,我已经解决了这个问题。 file.exists()返回true,但是,当我试图把它放在扫描仪,它会抛出filenotfoundexception 这是我所有的代码 import java.util.Scanner; import java.io.*; public class readInt{ public static void main(String args[]){ File file=new File("lines.txt"); System.out.println(file.exists()); Scanner scan=new Scanner(file); } }