Today, I am writing a program for transmitting images through the mobile phone and PC WebService (implemented using axis2). The server is a class and is directly deployed in the pojo folder of axis after compilation, when I create a new fileinputstream, I want to use a relative path so that no matter where my server is deployed, I can always use a folder without having to modify the program path code, of course, first of all, I use absolute paths for experiments to ensure successful communication. When using absolute paths, note that the path separator can be "/" or "\". this can also be mixed as follows:
Fileinputstream FCM = new fileinputstream ("D:/images/" + ID + ". jpg ");
Or
Fileinputstream FCM = new fileinputstream ("D: \ images \" + ID + ". jpg ");
Yes.
It can even be used in combination.
Then I want to use the relative path, but when I compare the images folder with my. when the class file (WebService to be executed) is placed in the same directory, it is found that the operation failed and the folder cannot be found. The Code is as follows:
Fileinputstream FCM = new fileinputstream ("images/" + ID + ". jpg ");
Then I printed the current directory using system. Out. println (new file ("."). getabsolutepath ();
The result is the bin directory of Tomcat, instead of the WebService directory of Tomcat, which is modified as follows:
Fileinputstream FCM = new fileinputstream ("../webapps \ axis2 \ WEB-INF/pojo/images/" + ID + ". jpg ");
Note: ../indicates the upper-level directory of the current directory.
Therefore, if you want to use the current directory when deploying it as a WebService to Tomcat, you 'd better use system first. out. println (new file (". "). getabsolutepath (); check what the current directory is, because it is not necessarily yours. the directory where class files are stored, usually
Tomcat bin directory, so you need to re-specify the directory you want to reach based on this directory.