Re: Accessing files within JAR archive
From: Alex Kizub (akizub_at_yahoo.com)
Date: 10/30/03
- Next message: Randolph M. Jones: "Re: Why?"
- Previous message: VisionSet: "Re: Why?"
- In reply to: Anthony Borla: "Re: Accessing files within JAR archive"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 30 Oct 2003 09:51:23 -0800
String file="test.txt";
URL url = getClass().getResource("/file/txt/"+file);
if (url == null) {
System.out.println(
"File "+file+" do not exist.");
break;
}
URLConnection conn = url.openConnection();
InputStream istream = conn.getInputStream();
Important thing is "/file/txt/"!
This is path inside jar.
If you use just file it means current directory and it means where is
you class located.
So, if you call this method in class a.b.Test then it will
read /a/b/file.txt inside jar.
Alex Kizub.
- Next message: Randolph M. Jones: "Re: Why?"
- Previous message: VisionSet: "Re: Why?"
- In reply to: Anthony Borla: "Re: Accessing files within JAR archive"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|