标签: filenotfoundexception

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:    at com.phonegap.AudioHandler.startPlayingAudio(AudioHandler.java:181)
05-31 13:23:04.235 18440 18603 W System.err:    at com.phonegap.AudioHandler.execute(AudioHandler.java:64)
05-31 13:23:04.235 18440 18603 W System.err:    at com.phonegap.api.PluginManager$1.run(PluginManager.java:86)
05-31 13:23:04.235 18440 18603 W System.err:    at java.lang.Thread.run(Thread.java:1096)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

java android filenotfoundexception cordova

37
推荐指数
6
解决办法
3万
查看次数

Java - 拒绝访问java.io.FileNotFoundException

我有以下代码:

List<FileItem> items = uploadHandler.parseRequest(request);
for (FileItem item : items) {
    if (!item.isFormField()) {
        File file = new File("D:/Data");
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试保存文件时,我收到以下错误

java.io.FileNotFoundException: D:\Data (Access is denied.)
Run Code Online (Sandbox Code Playgroud)

可能是什么原因,我该如何解决这个问题?我对此文件夹有读写权限.

java filenotfoundexception

37
推荐指数
4
解决办法
20万
查看次数

Windows 10更新后,System.DirectoryServices.AccountManagement.PrincipalContext中断

在过去的几年里,我一直在使用这个小功能,没有任何问题来验证用户凭据.该createPrincipalContext方法返回PrincipalContextwith ContextType.Machine和机器名称.

public static bool ValidateCredentials(string username, string password, string domain = null) {
    try {
        using (var principalContext = createPrincipalContext(username, domain)) {
            username = GetLoginInfo(username).Username;
            // validate the credentials
            if (principalContext.ValidateCredentials(username, password)) {
                //once valid check if account is enabled
                using (UserPrincipal user = UserPrincipal.FindByIdentity(principalContext, username)) {
                    return user.Enabled.GetValueOrDefault(false);
                }
            }
        }
    } catch (PrincipalOperationException e) {
        traceError(e);
    } catch (Exception e) {
        traceError(e);
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

我的开发机器最近自动更新到最新版本的Windows 10,从那时起,principalContext.ValidateCredentials一直抛出以下异常.

System.IO.FileNotFoundException:系统找不到指定的文件.

除了机器更新,没有其他更改.我花了最近几天在网上搜索可能导致问题的原因. …

c# filenotfoundexception principalcontext

34
推荐指数
2
解决办法
1万
查看次数

Java Files.write NoSuchFileException

我正在尝试使用Files.write()方法将一些文本写入文件.

byte[] contents = project.getCode().getBytes(StandardCharsets.UTF_8);

try {
    Files.write(project.getFilePath(), contents, StandardOpenOption.CREATE);
} catch (IOException ex) {
    ex.printStackTrace();
    return;
}
Run Code Online (Sandbox Code Playgroud)

根据API,如果文件不存在,它将被创建然后写入.

但是,我明白了:

java.nio.file.NoSuchFileException: C:\Users\Administrator\Desktop\work\Default.txt
    at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
    at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
    at java.nio.file.spi.FileSystemProvider.newOutputStream(Unknown Source)
    at java.nio.file.Files.newOutputStream(Unknown Source)
    at java.nio.file.Files.write(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

java file-io file filenotfoundexception

33
推荐指数
1
解决办法
5万
查看次数

Java new File()表示FileNotFoundException,但文件存在

我有一个CS课程的作业,它说要读取一个包含多个考试成绩的文件,并要求我对它们进行求和.虽然求和和平均很容易,但我在阅读文件方面遇到了问题.讲师说要使用这种语法

Scanner scores=new Scanner(new File("scores.dat"));
Run Code Online (Sandbox Code Playgroud)

但是,这会抛出一个FileNotFoundException,但是我一遍又一遍地查看当前文件夹中是否存在该文件,之后,我认为它必须对权限做一些事情.我为每个人更改了读写权限,但它仍然无法正常工作,但仍然会抛出错误.有谁知道为什么会这样?

编辑:它实际上是指向一个目录,但是,我已经解决了这个问题.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);
        }
}
Run Code Online (Sandbox Code Playgroud)

java filenotfoundexception

32
推荐指数
5
解决办法
19万
查看次数

调用webservice时出现FileNotFoundException

您好,我已经解决了我最初的问题.我是一个完整的Android菜鸟,这是我的第一个应用程序.我正在Android模拟器上测试它.我尝试连接到.NET Web服务http://192.168.3.47/service.asmx.我得到了FileNotFoundException.但它就在那里,网址是正确的.我怎么能让他看到这个?


03-03 11:23:49.741: WARN/System.err(455): java.io.FileNotFoundException: http://192.168.3.47/service.asmx
03-03 11:23:49.751: WARN/System.err(455):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:521)
03-03 11:23:49.801: WARN/System.err(455):     at gyozo.HelloWorld.HelloActivity.onClick(HelloActivity.java:62)
03-03 11:23:49.831: WARN/System.err(455):     at android.view.View.performClick(View.java:2485)
03-03 11:23:49.851: WARN/System.err(455):     at android.view.View$PerformClick.run(View.java:9080)
03-03 11:23:49.871: WARN/System.err(455):     at android.os.Handler.handleCallback(Handler.java:587)
03-03 11:23:49.910: WARN/System.err(455):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-03 11:23:49.940: WARN/System.err(455):     at android.os.Looper.loop(Looper.java:123)
03-03 11:23:49.950: WARN/System.err(455):     at android.app.ActivityThread.main(ActivityThread.java:3683)
03-03 11:23:50.010: WARN/System.err(455):     at java.lang.reflect.Method.invokeNative(Native Method)
03-03 11:23:50.050: WARN/System.err(455):     at java.lang.reflect.Method.invoke(Method.java:507)
03-03 11:23:50.070: WARN/System.err(455):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-03 11:23:50.090: WARN/System.err(455):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-03 11:23:50.110: WARN/System.err(455):     at …
Run Code Online (Sandbox Code Playgroud)

java android web-services filenotfoundexception

20
推荐指数
2
解决办法
3万
查看次数

尽管chmod 777,java.io.FileNotFoundException(权限被拒绝)

在Tomcat上编写Grails应用程序时,我遇到了奇怪的问题.

创建简单的测试控制器后,我想在包com中编写测试内容

package com.domain.controller

import java.io.File;
import java.io.PrintWriter;

class TestController {

        def index() {
                // test
                try {
                        PrintWriter writer = new PrintWriter("/home/user/domains/domain.com/public_html/the-file-name.txt");
                        writer.println("The first line");
                        writer.println("The second line");
                        writer.close();
                } catch (IOException e) {
                        throw new RuntimeException(e);
                }
        }
}
Run Code Online (Sandbox Code Playgroud)

我得到一个例外:

类java.io.FileNotFoundException消息/home/user/domains/domain.com/public_html/the-file-name.txt(Brakdostępu)

我已将chmod设置为777 /home/user/domains/domain.com/public_html/.而且tomcat7.tomcat7是老板.我还尝试使用访问权限777和所有权设置为tomcat7创建此文件,但我仍然得到一个例外:

ls -al /home/user/domains/domain.com/public_html
razem 16
drwxrwxrwx 3 tomcat7 tomcat7 4096 01-08 23:25 .
drwxr-xr-x 8 user    user    4096 12-16 17:14 ..
-rwxrwxrwx 1 tomcat7 tomcat7    0 01-08 23:25 the-file-name.txt
Run Code Online (Sandbox Code Playgroud)

我应该在OS中遇到什么条件?

如果有人能澄清问题,我将非常感激.


编辑 …

java grails tomcat filenotfoundexception ioexception

20
推荐指数
2
解决办法
5万
查看次数

从资源目录中读取文件会引发FileNotFoundException

我正在尝试阅读一些文字文件中的一些单词,我想用于我正在写的文字游戏.此列表存储在assets目录中,是一个txt文件.但是,每当我尝试打开它时,它都会引发异常.

List<String>wordList = new ArrayList<String>();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(getAssets().open("wordlist.txt"))); //throwing a FileNotFoundException?
        String word;
        while((word=br.readLine()) != null)
        wordList.add(word); //break txt file into different words, add to wordList
    }
        catch(IOException e) {
            e.printStackTrace();
        }
        finally {
            try {
                br.close(); //stop reading
            }
            catch(IOException ex) {
                ex.printStackTrace();
            }
        }
        String[]words = new String[wordList.size()];
        wordList.toArray(words); //make array of wordList

        for(int i=0;i<words.length; i++)
            Log.i("Brian", words[i]); //print out words in array
}
Run Code Online (Sandbox Code Playgroud)

这是错误日志,如果有任何帮助:

02-22 20:49:47.646: WARN/System.err(2351): java.io.FileNotFoundException: wordlist.txt …
Run Code Online (Sandbox Code Playgroud)

android filenotfoundexception bufferedreader android-assets

18
推荐指数
1
解决办法
3万
查看次数

src/main/resources中的FileNotFoundException

我在src/main/resources下的maven项目中放置了一个文件,文件名只是temp.txt.

当我尝试打开文件时:

BufferedReader br = new BufferedReader(new FileReader(new File("./temp.txt")));
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

Exception in thread "main" java.io.FileNotFoundException: \temp.txt
Run Code Online (Sandbox Code Playgroud)

src/main/resources下的所有文件都放在maven下的classpath的根文件夹中.那么为什么程序无法在这里找到文件呢?

java filenotfoundexception maven

18
推荐指数
2
解决办法
4万
查看次数

尝试将文件写入Android中的SD卡时,FileNotFoundException(权限被拒绝)

正如你可以从标题中注意到的那样,我在Android中将文件写入sdcard时遇到了问题.我已经检查了这个问题,但它没有帮助我.我想写一个将在sdcard上的公共空间中的文件,以便任何其他应用程序都可以读取它.

首先,我检查是否安装了SD卡:

Environment.getExternalStorageState();
Run Code Online (Sandbox Code Playgroud)

然后,我运行此代码:

File baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    baseDir.mkdirs();
    File file = new File(baseDir, "file.txt");
    try {
        FileOutputStream out = new FileOutputStream(file);
        out.flush();
        out.close();
        Log.d("NEWFILE", file.getAbsolutePath());
    } catch (IOException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

我有:

<manifest>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application>
...
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

在我的AndroidManifest.xml中.

确切的错误是这样的:

java.io.FileNotFoundException: /storage/1510-2908/Download/secondFile.txt: open failed: EACCES (Permission denied)
Run Code Online (Sandbox Code Playgroud)

我正在模拟器上测试我的代码(模拟Nexus5 API 23).我所需的最低SDK版本是19(4.4 Kitkat).


此外,一切正常,使用相同的代码将文件写入SD卡上的私人文件夹,所以我说前代码也应该工作:

File newFile = new File(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS), "esrxdtcfvzguhbjnk.txt");
    newFile.getParentFile().mkdirs();
    try {
        FileOutputStream out = new FileOutputStream(newFile);
        out.flush();
        out.close();
        Log.d("NEWFILE", newFile.getAbsolutePath());
    } catch (IOException e) …
Run Code Online (Sandbox Code Playgroud)

java android filenotfoundexception android-permissions

17
推荐指数
1
解决办法
3万
查看次数