Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-core-dev] Getting the input stream for a resource - can't be that difficult!

Hello folks,
 
I need to read the content of a (text) file which is part of my plug-in.
I found a way to do this, but I feel I did it in a rather awkward
manner. Look at what I wrote:
 
=====snip======= 
    	String path = "/data/myData.txt" ;
    	Bundle b = Platform.getBundle(PLUGIN_NAME);
    	URL url = Platform.find(b, new Path(path));
    	URL localUrl = null ;
    	InputStream is = null ;
    	InputStreamReader isr = null ;
    	try {
			 localUrl = Platform.resolve(url);
			 is = localUrl.openStream();
			 isr = new InputStreamReader(is);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
=====snap=======

The key seems to be to get an IFile for my URL, then the IFile will give
me the InputStream. But I could not figure out how to do this, hence the
hack (?) with Platform.resolve() and the localURL. 
Or is this actually the way it must be done?

All hints appreciated.


Norbert 


Back to the top