How to read a file (e.g txt file) from another java package withouth specifying the absolute path? -


i have stored non-java files in package. want read files package without specifying absolute path file(e.g c:\etc\etc...). how should this?

use getresourceasstream

for example:

myclass.class.getresourceasstream("file.txt"); 

will open file.txt if it's in same package myclass

also:

myclass.class.getresourceasstream("/com/foo/bar/file.txt"); 

will open file.txt on package com.foo.bar

good luck! :)


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -