File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
RabbitMQ in Depth
this week in the
new File (Relative Path to a package): How?
Joined: Jul 26, 2011
Aug 16, 2011 21:13:53
1. I used Apache common io.
> 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?
Joined: Oct 14, 2005
Aug 16, 2011 22:53:34
First you get a File object which represents the "package" -- whatever you mean by that.
File packageFile = ...
Then you use the File constructor which allows you to create a File relative to another File:
File dataFile = new File(packageFile, "mypackage/io/textfile.txt");
I agree. Here's the link:
subject: new File (Relative Path to a package): How?
Writting a String to a file
Send lines of a file to something such as an arrayList
Not able to find a File in servlet
genarate PDf and save it on server
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015