标签: filenotfoundexception

文件存在时抛出FileNotFoundException

我正面临这个奇怪的问题.

我正在尝试将位于另一台计算机上的文件作为共享资源读取:

\\remote-machine\dir\MyFileHere.txt
Run Code Online (Sandbox Code Playgroud)

当我运行一个独立的应用程序(16行java文件)时,一切都很好.但是,当我尝试使用相同的类和相同的方法从服务器"引擎"(这是一个应用程序引擎,非常类似于Java EE Application Server,您可以运行Java程序)读取相同的文件时,"FileNotFoundException"被扔了.

我虽然我会获得某种权限,所以我将资源映射为驱动器:K:\

重新运行我的java文件,读取,很好.

在"引擎" - > FileNotFoundException中重新运行我的java文件.

当我将文件复制到本地计算机(C:\ MyFileHere.txt)时,不会抛出异常.

可能导致此FileNotFoundExcecption的原因是什么?

我正在使用Java 1.5

据我所知,引擎几乎透明地使用java.

任何人都面临类似的事情?

附加问题?什么是解决此问题的好方法?我开始考虑提供服务这些文件的tomcat安装并通过http读取它们,但我认为这太多了,这就是为什么SMB协议首先用于它的原因不是吗?也许我无论如何都无法打开插座.

安全管理器可能是原因(我之前从未使用过,但我知道它存在)

如果出现这种情况,是否会抛出SecurityException?

非常感谢.

编辑

解决了.谢谢史蒂夫W.

事实证明,该引擎是使用ZeroG的"LaunchAnywhere"启动的.因此,创建一个.exe,然后将使用指定的应用程序运行JVM.

它自己的这个应用程序是Launcher.当它启动引擎时,不知何故(我无法弄清楚为什么或如何)拥有JVM进程的用户是SYSTEM.史蒂夫指出,该用户没有NETWORK访问权限,因此无法从共享资源或映射驱动器中读取.

解决方法(当我向制造商报告时)是创建一个.cmd文件来手动启动引擎.由于它将手动启动,因此用户可以访问网络.

我使用了SysInternals的"Process Explorer"来确切地知道用于运行引擎应用程序的命令行.

真是一团糟!

感谢那些发布答案的人.

java io smb jvm filenotfoundexception

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

Android FileNotFound异常 - 无法从没有文件格式的图像URL获取getInputStream

标题非常自我解释.

以下代码......:

    URL imageUrl = new URL(url);
   try {
                HttpURLConnection conn= (HttpURLConnection)imageUrl.openConnection();
                conn.setDoInput(true);
                conn.connect();
                int length = conn.getContentLength();
                InputStream is = conn.getInputStream();
                return BitmapFactory.decodeStream(is);
           } catch (IOException e) {
            e.printStackTrace();
           }
Run Code Online (Sandbox Code Playgroud)

如果url不包含文件格式,则会失败.例如,谷歌托管的一些图像将显示图像,但不具有文件格式(.png,.jpg等)作为网址的一部分.

因此,url连接的content-type标头返回"text/html".我相信这是个问题.

我试过设置一个新的内容类型标题,但似乎没有改变任何东西.

有人知道解决方法吗?

谢谢.

java android image filenotfoundexception httpurlconnection

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

错误无法加载文件或程序集“ Interop.ActiveDs”

我正在使用C#执行一些活动目录,并且在页面上收到此错误

System.IO.FileNotFoundException: Could not load file or assembly 'Interop.ActiveDs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=46db4b78e98e1c9d' or one of its dependencies. The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)

我在64位计算机上添加的ActiveDS参考存在一些问题,它运行的服务器也是x64

我添加了ActiveDS参考,因此可以执行以下操作

newRoleGroup.Properties["groupType"].Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_UNIVERSAL_GROUP;
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,为什么它不能加载ActiveDs参考?

c# asp.net filenotfoundexception active-directory

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

fileNotFoundException但文件存在

在我的FileInputStream中我得到一个FileNotFoundException,但我知道他的文件存在,我可以用webbrowser下载它.

如果我将链接从异常复制到webbrowser,它也可以工作.对于每个人来说,RWX都有权利进行测试,但这没有用.

文件名中没有特殊标志......我不知道为什么会失败..

thx 4帮助!

编辑:

KeyStore ts = KeyStore.getInstance("PKCS12");
ts.load(new FileInputStream("http://192.168.1.1/ordner/myFile.p12"), passwKey);
KeyManagerFactory tmf = KeyManagerFactory.getInstance("SunX509");
tmf.init(ts, passwKey);
Run Code Online (Sandbox Code Playgroud)

出于安全原因,我更改了链接

java file filenotfoundexception

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

线程"main"中的奇怪异常java.io.FileNotFoundException I/O Java

我在尝试读取文件时遇到此错误:

Exception in thread "main" java.io.FileNotFoundException: \src\product.txt (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at dao.Inventory.readFile(Inventory.java:30)
at view.InventoryView.init(InventoryView.java:33)
at view.InventoryView.<init>(InventoryView.java:21)
at view.InventoryView.main(InventoryView.java:211)
Run Code Online (Sandbox Code Playgroud)

但问题是,我的src文件夹中有product.txt.

我的代码如下:

  public void readFile() throws IOException {
            // input file must be supplied in the first argument
            InputStream istream;
                    File inputFile = new File("\\src\\product.txt");
                    istream = new FileInputStream(inputFile);

                    BufferedReader lineReader;
                lineReader = new BufferedReader(new InputStreamReader(istream));
                    String line;

                        while ((line = lineReader.readLine()) != null) {

                StringTokenizer tokens = new StringTokenizer(line, "\t");

                // String tmp = …
Run Code Online (Sandbox Code Playgroud)

java file-io filenotfoundexception

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

图像上传到Grails中的文件系统

我正在为Grails中的Web应用程序实现文件上传功能.这包括调整现有代码以允许多个文件扩展名.在代码中,我实现了一个布尔值来验证文件路径是否存在,但我仍然得到一个FileNotFoundException,/hubbub/images/testcommand/photo.gif (No such file or directory)

我的上传代码是

def rawUpload = {       
    def mpf = request.getFile("photo")
    if (!mpf?.empty && mpf.size < 200*1024){
        def type = mpf.contentType
        String[] splitType = type.split("/")

        boolean exists= new File("/hubbub/images/${params.userId}")

        if (exists) {
            mpf.transferTo(new File("/hubbub/images/${params.userId}/picture.${splitType[1]}"))
        } else {
            tempFile = new File("/hubbub/images/${params.userId}").mkdir()
            mpf.transferTo(new File("/hubbub/images/${params.userId}/picture.${splitType[1]}"))
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

我收到了异常消息

if (exists) {
        mpf.transferTo(new File("/hubbub/images/${params.userId}/picture.${splitType[1]}"))
}
Run Code Online (Sandbox Code Playgroud)

那么,为什么会发生这种错误,因为我只是简单地折叠有效的现有路径以及有效的文件名和扩展名?

grails filenotfoundexception image-upload

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

导出为.jar文件后的FileNotFoundException

我正在使用Eclipse并开发一个使用本地文件的java应用程序.该文件位于项目文件夹内,在子文件夹中,说"mydata/myfile.txt"当我从eclipse运行应用程序时一切正常,我打开一个FileInputStream,传递"mydata/myfile.txt"作为名称,文件是读得很好.但是当我将我的应用程序导出为.jar并尝试运行它时,我得到的只是控制台中的FileNotFoundException.

如何导出程序以便它可以在任何计算机上运行并能够访问该文件?先感谢您.

java jar filenotfoundexception

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

在Java main方法中获取资源

我正在尝试通过调用MainClass.class.getResource("/Resources/file.extension")并将其传递给File的构造函数来在我的Java应用程序中打开资源getPath().接下来,当我初始化一个新FileInputStream的时File,我得到一个FileNotFoundException.完整的堆栈跟踪看起来如此.

java.io.FileNotFoundException: E:\user\Documents\NetBeansProjects\Project name\build\classes\Resources\file.csv (The system cannot find the path specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at my.secret.project.MainClass.main(MainClass.java:27)
Run Code Online (Sandbox Code Playgroud)

这是我的代码.

File file = new File(MainClass.class.getResource("/Resources/file.extension").getPath());

...

InputStream in = new FileInputStream(file);
Run Code Online (Sandbox Code Playgroud)

java resources filenotfoundexception

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

运行jar文件时出现FileNotFoundException

我有以下代码:

package test;


import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class SWTTest {

    public static void main(String[] args) {
        SWTTest test=new SWTTest(new Display());
        test.run();
    }


    private Shell shell;
    private Display display;


    public SWTTest(Display main_display) {
        display=main_display;

        shell=new Shell(display, SWT.DIALOG_TRIM);
        shell.setText("Test window");
        shell.setBackgroundImage(new Image(display,"./image/blue_screen.jpg"));
    }

    public void run() {

        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) 
                display.sleep();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是编译和运行.问题是当我将其导出为jar文件时.
只是为了确保我做得正确:
右键单击项目 - > export ...-> Runnable Jar文件 - >选择正确的启动配置,然后选择'完成'.
它创建了一个jar文件,但是当我从终端运行它时,我得到:

Exception in thread "main" org.eclipse.swt.SWTException: i/o error (java.io.FileNotFoundException: …
Run Code Online (Sandbox Code Playgroud)

java filenotfoundexception

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

无法使用Paths.get()从Maven资源加载文件

我为这个看似简单且几乎是一个愚蠢的问题道歉,但我花了很多时间来修复它而没有太大的成功.

我创建了一个非常简单的maven项目,然后在这个src/resources文件夹中创建了一个简单的文本文件.

在此输入图像描述

在此输入图像描述

pom.xml很简单.这个App类看起来像这样:

public class App {
    public static void main(String[] args) throws IOException {
        Files.lines(Paths.get("test.txt")).forEach(System.out::println);
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的例外:

Exception in thread "main" java.nio.file.NoSuchFileException: test.txt
    at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
    at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
    at java.nio.file.Files.newByteChannel(Files.java:361)
    at java.nio.file.Files.newByteChannel(Files.java:407)
    at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
    at java.nio.file.Files.newInputStream(Files.java:152)
    at java.nio.file.Files.newBufferedReader(Files.java:2784)
    at java.nio.file.Files.lines(Files.java:3744)
    at java.nio.file.Files.lines(Files.java:3785)
    at com.rahul.App.main(App.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

这似乎是一个非常愚蠢的问题,但我无法理解它.任何帮助都是真诚的感谢.

java filenotfoundexception maven java-8 nosuchfileexception

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