Java使用pdfviewer显示资源文件夹中存在的文件

Java使用pdfviewer显示资源文件夹中存在的文件,java,pdf,resources,filenotfoundexception,Java,Pdf,Resources,Filenotfoundexception,我有java web应用程序。我正在使用ANT构建应用程序。我在resources文件夹中有一个文件。我想用pdfViewer打开那个文件。pdf查看器的框架即将启动。但我无法访问资源文件夹中的文件。这是我的密码 final String fileName="Installation.pdf"; int pagenum = 0; RandomAccessFile raf = new RandomAccessFile (new File(fileName), "r"); FileChannel

我有java web应用程序。我正在使用
ANT
构建应用程序。我在resources文件夹中有一个文件。我想用pdfViewer打开那个文件。pdf查看器的框架即将启动。但我无法访问资源文件夹中的文件。这是我的密码

final String fileName="Installation.pdf"; 

int pagenum = 0;
RandomAccessFile raf = new RandomAccessFile (new File(fileName), "r");
FileChannel fc = raf.getChannel ();
ByteBuffer buf = fc.map (FileChannel.MapMode.READ_ONLY, 0, fc.size ());
PDFFile pdfFile = new PDFFile (buf);
我收到一个
FileNotFoundException
。主要问题是我无法在resources文件夹中找到该文件。请帮忙

当我将其作为一个独立的java应用程序运行时,上面的代码工作正常

试试这个:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
URL url = classLoader.getResource("/resources/Installation.pdf");

if (url != null) {

    try {
        RandomAccessFile raf = new RandomAccessFile (new File(url), "r");

        ...

    } finally {
        input.close();
    }
}

你能提供你的目录层次结构吗?DYM所说的“pdfViewer”是指一个特定的API,还是指一个PDF文档的通用查看器?你可以只打开文件而不是启动PDF查看器。人们通常对pdf文件有正确的系统关联。下面是相关的答案:现在我看到这个问题不是关于ant的,所以我要去掉这个标签。构建应用程序的内容应该无关紧要,只有jar和类路径的内容。这个问题真的是关于pdf的吗?如果在
newfile
call中出现异常,为什么要询问PDF?也许这是一个副本:。你能帮我解决这个问题吗?