| 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: 2906
|
|
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
|
"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
|
 |
 |
|
|
subject: Axis2: Read/Write file with absolute path‏
|
|
|