This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services and the fly likes Axis2: Read/Write file with absolute path‏ Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Axis2: Read/Write file with absolute path‏" Watch "Axis2: Read/Write file with absolute path‏" New topic
Author

Axis2: Read/Write file with absolute path‏

Janfry Nice
Greenhorn

Joined: Oct 10, 2005
Posts: 7
Hi.

This must be a newbie question but I haven't found how to resolve it.

I'm using Windows, Tomcat 5.5 and Axis 1.3.

I want to read (and write) files that are in directories not included in the classpath.

The following method to read a file and returning the contents into a String:

public static String readFile2String(String file) throws Exception {
String content = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
int x = fis.available();
byte b[] = new byte[x];
fis.read(b);
content = new String(b);
} finally {
if (fis != null) {
fis.close();
}
}
return content;
}

works with these calling lines in a standalone program:

public static void main(String[] args) throws Exception {
System.out.println("FILE CONTENTS=" + readFile2String("W:\\tests\\data\\fich00.dat"));
}

However, when executed

readFile2String("W:\\tests\\data\\fich00.dat")

within the web service, it generates "java.io.FileNotFoundException".

I have tried too using / instead of \\, but it doesn't work.

Must I configure anything in Tomcat and/or Axis2 to access any file or directory not included in classpath? Perhaps is a Security problem?

NOTE: I do NOT want to include those files into "lib" or "classes" directory, and how the files are not
in the classpath, getClassLoader().getResource() or getResourceAsStream I know doesn't work.

Thanks in advance,

Janfry
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Originally posted by Janfry Nice:
Perhaps is a Security problem?


If Tomcat is running as a service it may be be using a less privileged user account (one that can't even "see" the file) than the user account that you are using to run the standalone program.
The Apache Tomcat 5.5 Servlet/JSP Container: Windows service HOW-TO

Of course once Tomcat can see the file you may very well face: "access denied (java.io.FilePermission...)"
The Apache Tomcat 5.5 Servlet/JSP Container: Security Manager HOW-TO
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Axis2: Read/Write file with absolute path‏
 
Similar Threads
InvalidFormatException
how to put two different folders(which is in different location) into one zip entry
I need help with custom ClassLoader's
how to read a file data into byte array
Problem in Locating a properties File (Not the Struts application.properties)