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();
}
}
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