I get the below exception.
Failed to GET File Details from http://192.168.2.111/storage java.io.FileNotFoundException: http:/192.168.2.111/storage/data/18-Apr-2017-ops (No such file or directory)
junit.framework.AssertionFailedError: Failed to GET File Details from http://192.168.2.111/storage java.io.FileNotFoundException: http:/192.168.2.111/storage/data/18-Apr-2017-ops (No such file or directory)
at com.billing.getlogs.GetLogsTest.countLinesOperationsUpload(GetLogsTest.java:222)
at com.billing.getlogs.GetLogsTest.GetLogsLineCountTest(GetLogsTest.java:264)
If you look, the URL after java.io.FileNotFoundException: only has one / in the after http:. The URL is read from a properties file. Is there any reason why this would be getting removed as the / character correctly appears in other parts of the url.
Got it.
I changed
InputStream is = new BufferedInputStream(new FileInputStream(text));
to
InputStream is = new BufferedInputStream(new URL(text).openStream());
I had been trying to read the contents of a URL but my original code was for reading the contents of a file.
Related
Im trying to read the parquet footer file to get the page count, So I can return the value from API that I have created. The code that i have written is as below.
File file = new File(filepath);
Configuration conf = new Configuration();
org.apache.hadoop.fs.path parquetFilePath = new
org.apache.hadoop.fs.path(file.getAbsolutePath());
ParquetMetadata readFooter =
org.apache.parquet.hadoop.ParquetFileReader.readFooter(conf,parquetFilePath, NO_FILTER);
When I execute the last line of code that is going to read the footer of the parquet file it is giving me file not found exception (Access is denied) but actually file is present at the location. I have also given all the read and write permissions using the security tab by right clicking on the properties option
i was trying to use a txt file but i got this eror "FileNotFoundException"
but it was readable and it exist but on line FileInputStream i got that error
whats the matter?
System.out.println(Files.isReadable(Paths.get("I:/Code/Coding/src/Files/" + path + ".txt")));
System.out.println(Files.exists(Paths.get("I:/Code/Coding/src/Files/" + path + ".txt")));
FileInputStream f1=new FileInputStream("I:/Code/Coding/src/Files/" + path + ".txt");
reader = new ObjectInputStream(f1);
java.io.FileNotFoundException: I:\Code\Coding\src\Files\Artists.txt (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at sample.Datebase.Server.readFiles(Server.java:70)
at sample.Datebase.Server.run(Server.java:99)
at sample.Datebase.Server.main(Server.java:54)
Exception in thread "main" java.lang.NullPointerException
at sample.Datebase.Server.readFiles(Server.java:94)
at sample.Datebase.Server.run(Server.java:99)
at sample.Datebase.Server.main(Server.java:54)
I had the same problem and i solved it by using File class. Please try this code. maybe your problem will be solved :
File file = new File("I:/Code/coding/src/Files/" + path + ".txt");
reader = new ObjectInputStream(new FileInputStream(file));
Object o = reader.readObject();
The first 3 lines of this code snippet looks ok, ideally it should not throw a FileNotFoundException if the Files.exists, and Files.isReadable gives true.
But you can not use an ObjectInputStream to read a normal text file, as it will look for certain file headers to interpret the java object serialized.
Can you please copy paste the exception trace ?
FileNotFoundException - if the file exist but cannot be opened for reading then also throws FileNotFoundException exception
Read for Details FileInputStream
First, check the permission of that file. Is it opened for reading or not.
public static boolean isReadable(Path path): return true if the file
exists and is readable but it is not guaranteed; Note that the result of this
method is immediately outdated, there is no guarantee that a
subsequent attempt to open the file for reading will succeed (or even
that it will access the same file). Care should be taken when using
this method in security sensitive applications.
I'm attempting to use the transferTo method on a MultipartFile, but I'm having issues in doing so. Below is my code:
String videoName = UUID.randomUUID().toString();
File tempVideoFile = new File("src/main/resources/static/campaigns/" + videoName);
//multipart file is video
video.transferTo(tempVideoFile); //this line is what causes an error
This ends up throwing an IOException saying the JVM cannot find the path specified. Here's the error:
Invalid file directoryjava.io.IOException: java.io.FileNotFoundException: C:\Users\Jake\workspace\Test App\src\main\resources\static\temp\work\Tomcat\localhost\ROOT\Test App\src\main\resources\static\campaigns\db95aad3-a3ba-489a-a02e-83f5beece9a7 (The system cannot find the path specified)
Not 100% certain as to why it's not working but I believe the proper directory should be src\main\resources\static\campaigns\db95aad3-a3ba-489a-a02e-83f5beece9a7 instead of the one inside of the Tomcat directory, but I'm not sure.
Any ideas as to why this won't work? The path src\main\resources\static\campaigns\ exists so I'm not sure why.
I'm trying to save an uploaded file to my disk like this:
Part filePart = req.getPart("pic");
String fileName = filePart.getSubmittedFileName();
InputStream fileContent = filePart.getInputStream();
File uploads = new File("/images/gin");
File file = new File(uploads, fileName);
if(!file.exists())
file.createNewFile();
Files.copy(fileContent, file.toPath());
Tomcat always gives me the exception:
java.io.IOException: No such file or directory
java.io.UnixFileSystem.createFileExclusively(Native Method)
java.io.File.createNewFile(File.java:1006)
com.springapp.mvc.servlets.AddItemServlet.doPost(AddItemServlet.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
I don't know why it isn't working. Someone that can help me?
Call uploads.mkdirs(); before the new file creation
mkdirs()
* Creates the directory named by this abstract pathname, including any
* necessary but nonexistent parent directories. Note that if this
* operation fails it may have succeeded in creating some of the necessary
* parent directories.
Check with uploads.getAbsolutePath() to see if it's mapping the relative path to the intended folder. If yes, see if the account running tomcat has read/write access to the folder.
Normally when using ...
Transformer t = TransformerFactory.newInstance().newTransformer();
t.transform(source,result);
(without the xmlparserv2.jar file) a File Not Found Exception looks like this.
Exception in thread "main" java.io.FileNotFoundException: C:\Documents and Settings\username\nonExistentFile.xml (The system cannot find the file specified)
when you include the xmlparserv2.jar, the Exception turns to this
Caused by: java.io.FileNotFoundException: C:\Documents%20and%20Settings\username\existingFile.xml (The system cannot find the path specified)
The file is actually there (the transform method finds it when i dont include the jar) but when i include the jar, the transform method cant find it due to the %20 that is inserted for whitespace. Can someone please tell me how to fix this?
Sorry, should have included more code... the answer was in the Result Object i was passing in.
originally it looked like this
File f = new File(filePath);
Result result = new StreamResult(f);
changed to this..
File f = new File(filePath);
StreamResult result = new StreamResult();
FileOutputStream fos = new FileOutputStream(f);
result.setOutputStream(fos);