This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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

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

H Paul
Ranch Hand

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

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

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

1M Thanks.
Paul Clapham

Joined: Oct 14, 2005
Posts: 19728

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:
Have you checked out Aspose?
subject: new File (Relative Path to a package): How?
It's not a secret anymore!