Sunday, January 27, 2013

How to get IFile from File object

In eclipse world you need IFile object is very import to IO operation in plugin. Following code sample shows how get IFile from File object 

  IWorkspace workspace= ResourcesPlugin.getWorkspace(); 
  Bundle bundle = FrameworkUtil.getBundle(Activator.class);
URL fileURL = bundle.getEntry("resouces/TestFile");
File file = new File(FileLocator.resolve(fileURL).toURI());
IPath location= Path.fromOSString(file.getAbsolutePath()); 
  IFile ifile= workspace.getRoot().getFile(location);

Following code sample shows how to get ICompilation unit using IFile ,
  
ICompilationUnit createCompilationUnitFrom = JavaCore. createCompilationUnitFrom(ifile);
Good Luck !!

No comments:

Post a Comment