I try to load the File from RAR . I am using the
sFileName=Thread.currentThread().getContextClassLoader().getResource("common.xml").getFile();
Immediately, my requirement is load the file in to File IO.
fSettings = new File(sFileName);
if (fSettings.exists() && fSettings.isFile()) {
Is it possible to load the File from classpath and Create File object? Would it be possible to validate?
Share your thoughts.
I get this following error:
22:44:16,718 ERROR [STDERR] java.io.FileNotFoundException: file:\C:\Servers\ApplicationServers\jboss-4.2.3.GA\server\XXXX\tmp\deploy\XXX.ear-contents\XXX.rar!\common.xml (The filename, directory name, or volume label syntax is incorrect)
22:44:16,718 ERROR [STDERR] at java.io.FileInputStream.open(Native Method)
The URL that you get with the getResource() might not be a file, and in this case it's not because your common.xml is inside of a RAR file. If you want to access common.xml, just do a getResourceAsStream() and read the InputStream.
Related
I am making a function to download a file from a server. The function to download the file works fine. However, when the user enters the file explorer and manually deletes the file and tries to download again, the error java.io.FileNotFoundException: /storage/emulated/0/Download/File.jpg: open failed: EEXIST (File exists) occurs. Is there a way to solve this without using the MANAGE_EXTERNAL_STORAGE permission?
File download is in progress with HTTPUriConnection, and it reads as inputstream and saves the file in the path designated as outputstream.
The download path I specified is "Environment.getExternalStorageDirectory().toString() + "/" + Environment.DIRECTORY_DOWNLOADS".
I am going to index files in a folder:
public static final String FILES_TO_INDEX_DIRECTORY = "src/";
File dir = new File(FILES_TO_INDEX_DIRECTORY); //ERROR
File[] files = dir.listFiles();
for (File file : files) {
...
But I got getting this exception:
Exception in thread "main" java.io.FileNotFoundException: src\main
(Access is denied) at java.io.FileInputStream.open(Native Method)
My project is in the desktop:
C:\Users\hamed\Desktop\SearchEngine
When building the Drools examples in Eclipse (Win7), I had Access Denied build errors like:
Caused by: java.io.FileNotFoundException: C:\opta\drools-distribution-7.7.0.Final\examples\sources\.classpath (Access is denied)
Checking file .classpath turned out to have hidden attribute set in Win7.
Unchecking the hidden attribute brought me to the next build error for .project.
Also hidden, and unchecking that gave immediate build success.
Which line causes the FileNotFoundException? If I try your code, the line marked // ERROR always works, both with valid as well as with non-existent file names.
I suspect the exception happens in a later line (which you have not given in your snippet).
It may actually really be what the error message says (access denied).
Check the file permissions. It can be tricky on Windows, when copying the files from somewhere else.
I have written a basic jsp code for storing and retrieving the data from db.
Before that am checking validation of user.
When i click submit button it will redirect to my jsp page.
i have written a db.properties file separately.
When i gave complete path to read properties file., program is executing fine. (Which is not best way to hard code like below).
FileInputStream in = new FileInputStream("C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\ServiceDisplay\db.properties");
But when i specify only "db.properties" like
(FileInputStream in = new FileInputStream("db.properties");) program is not executing i got file not found exception.
Please not this properties file is in current working dir only. (i.e., my db.properties file and my jsp file is under ServiceDisplay
I tried to changing the file name as "//db.properties", "/db.properties", "./db.properties", "\db.properties", .\db.properties, ../db.properties", "..\db.properties" .
But still i am getting java.io.FileNotFoundException: db.properties
The file 'ServiceDisplay\db.properties' is in your resources directory, to load this file is necessary to use the getResoursceAsStream. Code example below:
ServletContext context = request.getSession().getServletContext();
InputStream is = context.getResourceAsStream("/db.properties");
I have a web application that has the feature to upload PDF which is done by the following process:
Create a folder on user's local path ( C:/resource/pdf/ )
Write the PDF file inside the folder.
On my local(running on eclipse/tomcat) it can write the files directly but on the web I actually getting an error:
java.io.FileNotFoundException: C:\resource\pdf\Daily News.pdf (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
...
I'm using Spring MVC if it is related.
Is there a way to ask the user for a permission to write files in their local?
I am assuming you use a File object in your code; if so you can just do this:
File folder;
// set directory and everything
// create folder
folder.setWritable(true, true);
Then you can check if you can write with this:
write = folder.canWrite();
System.out.println(write);
I have been trying to run the pdf2text tool provided by apache. I initially got the 'failed to load main-class manifest attribute' error. So I modified the manifest file in the jar to include the Main-Class attribute. Wrote it as -
Main-Class: org.apache.pdfbox.ExtractText
But after this, I am getting the exception -
Exception in thread "main" java.io.FileNotFoundException:
org.apache.pdfbox.ExtractText (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:978)
at org.apache.pdfbox.ExtractText.startExtraction(ExtractText.java:196)
at org.apache.pdfbox.ExtractText.main(ExtractText.java:76)
What can possibly be the mistake here?
try to switch to this entry point (Main-class):
org.apache.pdfbox.PDFBox
edit: this setup should also work (if you want to extract text)
java -cp ./pdfbox-1.6.0.jar org.apache.pdfbox.PDFBox ExtractText some.pdf
note that you need to add Apache's logging package and so on to your CLASSPATH variable, unless you set that at the command line as well..