• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Wierd File Acess Error.

Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
In my code, I have this line:

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


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?
Posts: 22017
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Forget this weirdo. You guys wanna see something really neat? I just have to take off my shoe .... (hint: it's a tiny ad)
the value of filler advertising in 2020
    Bookmark Topic Watch Topic
  • New Topic