Thursday, May 2, 2013

Copy Resources from Eclipse Plug-in to Local File System

If we need to read a resource from an eclipse plugin and want to save it to local file system we can use following code :





















Following code will copy basicTemplate.diagram to local-file system:


private void copyTemplateToLocalDirectory() {

URI diagramTemplateFileUri = URI.createPlatformPluginURI(
"/dk.bording.viking.rcp.ui.till.editor/templates/basicTemplate.diagram", true);

URIConverter uriConverter = new ExtensibleURIConverterImpl();
try {

InputStream infile =  uriConverter.createInputStream(diagramTemplateFileUri);
FileOutputStream file = new FileOutputStream( new File(Platform.getInstanceLocation().getURL().getPath()+File.separator+NewFileName.diagram"));
file.write(ByteStreams.toByteArray(infile));
file.close();

} catch (IOException e1) {

e1.printStackTrace();
}

}





No comments:

Post a Comment

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...