简体   繁体   中英

FileOutputStream constructor is looking for file object in temp folder of tomcat instead of heap

In my program I am creating a file class object with a file name. After that to write into it I am creating a FileOutputStream object with the above file object.

File file = new File("mod.properties");
FileOutputStream fileOut = new FileOutputStream(file);

When it is running in the tomcat server, it is looking for the 'file' object in temp folder. Instead of the heap. And it is not happening in every tomcat server, but in few of them.

[Unable to fetch model from folder path /opt/tomcat/temp/1501748741522-0][STACK][java.io.FileNotFoundException: mod.properties (No such file or directory) at java.io.FileOutputStream.open0(Native Method) at java.io.FileOutputStream.open(FileOutputStream.java:270) at java.io.FileOutputStream.(FileOutputStream.java:213) at java.io.FileOutputStream.(FileOutputStream.java:162) at

From the java.io.File javadoc: " An absolute pathname is complete in that no other information is required in order to locate the file that it denotes. A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked."

You are setting a relative pathname when constructing File, so here you have your answer: those instances have different properties/settings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM