java.io.FileNotFoundException on Properties FileInputStream in CMD - java

I'm loading a Property file with the following method:
private final String utitt=Paths.get(".").toAbsolutePath().normalize().toString();//
...
properties.load(new FileInputStream(utitt+"/beallitasok/lang.set"));
...
This works fine within NetBeans without problems, but the jar file fails in command prompt:
java.io.FileNotFoundException: C:\java\IKE\dist\beallitasok\lang.set
(A rendszer nem találja a megadott fájlt)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at java.io.FileInputStream.(Unknown Source)
at IKE.IKE.fordit(IKE.java:1519)
at IKE.IKE.access$300(IKE.java:81)
at IKE.IKE$IngatlanokAblak.(IKE.java:9411)
at IKE.IKE.(IKE.java:544)
at IKE.IKE.main(IKE.java:697)
I've copied the "beallitasok" directory there (to c:\java\IKE\dist in my case), so the file is actually there. I'm using some files to translate certain strings and save/read some settings. I've checked whether i'm just blind, so just opened the file with a "more C:\java\IKE\dist\beallitasok\lang.set" command and it works.
Where or how shall i search for a clue? I'm not a pro, so thanks for any help.
PS: (A rendszer nem találja a megadott fájlt) = The System can't find the specified file. Translated from the Hungarian language.

Related

UnsatisfiedLinkError if app runs from Japanese folder

I get UnsatisfiedLinkError when trying to reach dll. This happens if bin folder is located in folder with Japanese name, system language and locale are set to Japan. I need to fix this.
In English environment and app located in Japanese named folder app does not run at all (fix unnecessary). In English environment and app located in English named folder app works fine.
Seems like NativeLibrary.load can not handle Japanese characters in library path.
Is this a bug in Java: https://bugs.openjdk.org/browse/JDK-8195129?
Error in console:
Exception in thread "main-FPSAWTAnimator-Timer0" java.lang.UnsatisfiedLinkError:
F:\Test\テスト\myApp\bin\jre\bin\jpeg.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter$1.run(JPEGImageWriter.java:180)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter$1.run(JPEGImageWriter.java:178)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageWriter.<clinit>(JPEGImageWriter.java:177)
at com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi.createWriterInstance(JPEGImageWriterSpi.java:96)
at javax.imageio.spi.ImageWriterSpi.createWriterInstance(ImageWriterSpi.java:351)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:843)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:827)
at sun.awt.datatransfer.DataTransferer.imageToStandardBytesImpl(DataTransferer.java:2203)
at sun.awt.datatransfer.DataTransferer.imageToStandardBytes(DataTransferer.java:2145)
at sun.awt.windows.WDataTransferer.imageToPlatformBytes(WDataTransferer.java:352)
at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1223)
at sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer.java:219)
at sun.awt.windows.WClipboard.setContentsNative(WClipboard.java:83)
at sun.awt.datatransfer.SunClipboard.setContents(SunClipboard.java:106)
at myPath.utils.c.<init>(Unknown Source)
at myPath.opengl.base.BaseViewer.renderSnapshot(Unknown Source)
at myPath.opengl.base.BaseViewer.access$1100(Unknown Source)
at myPath.opengl.base.e.a(Unknown Source)
at myPath.opengl.base.BaseViewer.render(Unknown Source)
at myPath.opengl.base.BaseViewer.display(Unknown Source)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
at com.jogamp.opengl.swt.GLCanvas$2.run(GLCanvas.java:153)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at com.jogamp.opengl.swt.GLCanvas$3.run(GLCanvas.java:165)
at com.jogamp.opengl.swt.GLCanvas.runInGLThread(GLCanvas.java:970)
at com.jogamp.opengl.swt.GLCanvas.display(GLCanvas.java:682)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:75)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:416)
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:172)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Paths:
F:\Test\テスト\myApp\bin\jre\bin\jpeg.dll
F:\Test\テスト\myApp\bin\appStarter.exe
Thanks for any hint!
Seems like the answer is here. sybase.allow.native.lib should be allowed:
System.setProperty("sybase.allow.native.lib", "true");
I need to run proper tests, but for now it seems to work.

"java.util.zip.ZipException: error in opening zip file" when trying to create a new JarFile

I'm trying to create a new JarFile using an existing File object but I keep getting a java.util.zip.ZipException: error in opening zip file.
I'm running the code below:
File x= new File("C:/Users/Priyanka/Documents/hello.java");
JarFile jarF = new JarFile(x);
when I run the code above I keep getting the error below:
Exception in thread "main" java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at prioritization.cfg.Test1.main(Test1.java:12)
I have tried this code on different machines and different version of eclipse but I keep getting the same issue.
I'm have tried to research the problem online but most of the solutions are about trying to open an existing .jar file.
Any help would be appreciated.
If you check the JavaDoc for the JarFile type, you'll see that it's only used for reading existing .jar files.
The JarFile class is used to read the contents of a jar file from any
file that can be opened with java.io.RandomAccessFile. - https://docs.oracle.com/javase/9/docs/api/java/util/jar/JarFile.html
To create a .jar file, you'll need to use a java.util.jar.JarOutputStream.

FileNotFoundException: path syntax wrong

I am trying to export my project as an executable jar file in eclipse.
My jar file looks like this:
\com
\de
\org
\res
I've got some xml files in the res folder and now I have some problems getting these files with the FileReader
java.io.FileNotFoundException: jar:file:\C:\Users\Patrick\Desktop\Brainwav3.jar!\res\de.xml (Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at de.brainwav3.language.LanguageHandler.load(LanguageHandler.java:98)
at de.brainwav3.core.Launch.main(Launch.java:24)
The path gets generated like this:
URL url = getClass().getResource("/res/de.xml");
FileReader reader = new FileReader(url.toString());
So I don't really have control over the path.
I resolved this problem with copying the required files next to the jar file and changing the url to another path but I want all ressources to be inside the jar file

How do I use mysqlimport?

Here is the command I am running using Runtime.getRuntime().exec() in Java:
mysqlimport --fields-terminated-by=, --lines-terminated-by="|" --local
--user=u --password=p DatabaseName
txtpath
Here is the error I get:
java.io.IOException: Cannot run program "mysqlimport": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at databaseCommunication.UploadThread.run(UploadThread.java:66)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 5 more
It seems like the problem should be that mysqlimport.exe is not installed or is not installed in the correct place, but I have tried downloading the mySQL utilities from http://dev.mysql.com/downloads/windows/installer/5.6.html and from https://dev.mysql.com/downloads/utilities/.
In order to make sure the problem was not that it could not find the file at "txtpath," I typed the full path into the command prompt, and the correct file was opened, so the error is definitely referring to mysqlimport.exe.
Googling my problem, the only threads I've been able to find refer to something called "Sqoop" which I am not familiar with, and they usually recommend downloading the mysql utilities.
For more context, I have been using BCP to upload data from a txt file to a sql server database, but now I need to do the same thing with mysql. If there is any way to use BCP (I'm pretty sure there isn't) or something else to bulk upload data from a local file I would be open to hearing that as well.
EDIT:
I am using Windows 8 on a remote desktop. I have manually added mysqlimport.exe to the PATH environment variable and it still gives the same error.
If you are on Windows, then try putting mysqlimport.exe as the command rather than just mysqlimport. If that still does not solve your problem, make sure that 'mysqlimport.exe' is in your PATH environment variable.

Writing a PDF file on the user local

My web application has a feature of uploading PDF files to the web that is executed the following proccess:
Create a folder which path is C:/resource/pdf/
Then write a PDF inside the folder
Is it possible for a web application to create a folder then write a PDF file inside it? I tried this and it is working perfectly fine, on my local. But when I deployed the app in the web ( free hosting ) there is an error:
java.io.FileNotFoundException: C:/resource/pdf/Daily News.pdf (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at com.neu.als.thesis.web.controllers.UploadController.writeFile(UploadController.java:129)
at com.neu.als.thesis.web.controllers.UploadController.uploadPDF(UploadController.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
I know lines 129 and 71. I tested it again in my eclipse and it is working. Is there any restriction on web application when it is deployed or anything similar that preventing me to create a folder?
Depending on your permissions on the server and who's account the server is running under, you may not have permissions to write to that directory. Typically, the safe bet for saving a file to the server locally is to create a temp directory or something inside of your apps directory structure to put the files in. You should have permission to write to that directory as long as it's in your apps file structure.

Categories