Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » How can I read or write the file in jar?
How can I read or write the file in jar? [message #461218] Sun, 07 January 2007 00:24 Go to next message
Eclipse UserFriend
Originally posted by: filot97.nate.com

My rcp package has the myRCP.jar in the plugin folder.
The myRCP.jar also has foo/property.xml file.
Then, how can I read or write the propety.xml.

Please, give me some code.
Thank you.
Re: How can I read or write the file in jar? [message #461219 is a reply to message #461218] Sun, 07 January 2007 04:33 Go to previous messageGo to next message
Eclipse UserFriend
You can't write to a Jar, but you can read from it by getClass().getResourceAsStream("/foo/property.xml") and then dealing with the returned InputStream. If you want to do writing of data then use the plugin's state location (from the bundle's getPluginStateLocation() if I remember) to read/write the file, and then use the property.xml as a template if there's no file in the property state location.

Alex.
Re: How can I read or write the file in jar? [message #461230 is a reply to message #461218] Sun, 07 January 2007 10:36 Go to previous messageGo to next message
Eclipse UserFriend
You might want to try something similar to the following:

private String getSchemaString() throws Exception
{
String schemaString = null;
try
{
JarFile jarFile = new JarFile (schemaJarFileName);
if (null == jarFile)
throw new Exception ("jarFile is null");


JarEntry schemaJarEntry = jarFile.getJarEntry("schema.ddl");
InputStream schemaInputStream = jarFile.getInputStream(schemaJarEntry);
int bytesAvailable = schemaInputStream.available();
char[] streamCharacterArray = new char [bytesAvailable];
InputStreamReader schemaInputReader = new InputStreamReader
(schemaInputStream);
schemaInputReader.read(streamCharacterArray);

schemaString = new String (streamCharacterArray);
return schemaString;
}// try
catch (Exception e)
{
System.out.println ("ERROR: getSchemaString() : " + e.toString());
throw new Exception (e);
}// catch (Exception e)
}// private String getSchemaString() throws Exception

Hope this helps,

Charlie

Oh Sangin wrote:
> My rcp package has the myRCP.jar in the plugin folder.
> The myRCP.jar also has foo/property.xml file.
> Then, how can I read or write the propety.xml.
>
> Please, give me some code.
> Thank you.
Re: How can I read or write the file in jar? [message #461243 is a reply to message #461230] Sun, 07 January 2007 14:23 Go to previous message
Eclipse UserFriend
Note that the 'getClass' method will access resources inside nested jars, whereas bundle.getEntry won't. Also, getClass will work when the library code is executed outside of the OSGi framework, whereas the latter will require the OSGi framework to be up and running in order to work.

Alex.
Previous Topic:How to set default key bindings?
Next Topic:Accessing the workbench from "outside" thread
Goto Forum:
  


Current Time: Wed Mar 19 16:36:51 EDT 2025

Powered by FUDForum. Page generated in 0.04034 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top