File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes new File (Relative Path to a package): How? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "new File (Relative Path to a package): How?" Watch "new File (Relative Path to a package): How?" New topic
Author

new File (Relative Path to a package): How?

H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 381
1. I used Apache common io.
2.
List<String> lines = FileUtils.readLines("c://etc...//mypackage//io//textfile.txt"); // absolute path
This is absolute path. It works.

3.
List<String> lines = FileUtils.readLines("mypackage/io/textfile.txt"); // relative to a package
Exception in thread "main" java.io.FileNotFoundException:

Syntax-wise or class-wise or xyz: How can I make it by using relative path to a package?

1M Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18136
    
    8

First you get a File object which represents the "package" -- whatever you mean by that.

Then you use the File constructor which allows you to create a File relative to another File:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new File (Relative Path to a package): How?
 
Similar Threads
Send lines of a file to something such as an arrayList
genarate PDf and save it on server
File Class
Not able to find a File in servlet
Writting a String to a file