aspose file tools*
The moose likes I/O and Streams and the fly likes Wierd File Acess Error. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Wierd File Acess Error." Watch "Wierd File Acess Error." New topic
Author

Wierd File Acess Error.

v ray
Ranch Hand

Joined: Mar 15, 2007
Posts: 223
Hi guys,
In my code, I have this line:


And this line looks for a specific file called "replacer.properties" under:

C:\Documents%20and%20Settings\ray\workspace\
.metadata\.plugins\org.eclipse.wst.server.core\tmp0\
wtpwebapps\project1\WEB-INF\classes\replacer.properties

This file is present under the location and is accessible when I click folder by folder and finally reach the "classes" folder, but when I copy the whole path to the browser and try to open it, it gives me a "unable to find file" error.

Likewise, my code throws a FileNotFound Exception, any ideas on why although the link exists, I cant access it when I try to copy the whole link?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

I think the %20 occurrences are the problem.

In URLs, spaces are replaced by %20. In file systems however, they are not.

You could try replacing every occurrence of %20 by a space, but that might break your code when run on a web server.


However, why use a FileInputStream? Besides "getResource(String name)" which returns a URL object, both ClassLoader and Class also have "getResourceAsStream(String name)" which returns an InputStream object. You can use this instead of your FileInputStream.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Hi.

You can try to find the file with a local look up (based on the package structure) using getClass().getResource(filename).
[ September 11, 2007: Message edited by: Leandro Melo ]

Leandro Melo
SCJP 1.4, SCWCD 1.4
Patrick Williams
Ranch Hand

Joined: Apr 03, 2005
Posts: 213
You can put replacer.properties along your classpath and your JVM should pick it up based on the relative reference to the filename alone. If you need to use an absolute path, try java.net.URLDecoder to resolve your %20s.


Patrick<br /> <br />SCJP/SCWCD/SCBCD/SCDJWS/SCEA<br /> <br />Currently working on:<br />SCJP 6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wierd File Acess Error.