File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
H Paul
Ranch Hand
Posts: 471
4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20184
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic