File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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

Axis2: Read/Write file with absolute path‏

Janfry Nice

Joined: Oct 10, 2005
Posts: 7

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];;
content = new String(b);
} finally {
if (fis != null) {
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


within the web service, it generates "".

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,

Peer Reynders

Joined: Aug 19, 2005
Posts: 2933
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 ("
The Apache Tomcat 5.5 Servlet/JSP Container: Security Manager HOW-TO
I agree. Here's the link:
subject: Axis2: Read/Write file with absolute path‏
It's not a secret anymore!