2011/07/24

Handling File in Eclipse Plugin


* Add Dependenceis in MANIFEST.MF
- MANIFEST.MF > Dependencies > Add > org.eclipse.core.resources


  1. IWorkspace ws = ResourcesPlugin.getWorkspace();   
  2. IWorkspaceRoot root = ws.getRoot();     
  3. IProject[] projects = root.getProjects();  
  4.   
  5. //ws.toString:org.eclipse.core.internal.resources.Worksapce@**  
  6. //root.toString : R  
  7.   
  8. IProject project = projects[0];  
  9. IFolder tmpDir = null;  
  10. IFile file = null;  
  11.     
  12. if(project.exists()){  
  13.   //1. Create in Project not System  
  14.   tmpDir = project.getFolder((new Path("tmp")));  
  15.   if(!tmpDir.exists()){  
  16.     try {  
  17.       //2. Create in System  
  18.       tmpDir.create(falsetruenull);  
  19.     }catch (CoreException e) {            
  20.       e.printStackTrace();  
  21.     }  
  22.   }  
  23.   file = tmpDir.getFile(new Path("boo.txt"));  
  24.   if(!file.exists()){  
  25.     try{          
  26.       String str = "dummy";  
  27.       InputStream is = new ByteArrayInputStream(str.getBytes());  
  28.       file.create(is, falsenull);            
  29.     }catch(CoreException e){  
  30.       e.printStackTrace();  
  31.     }  
  32.   }  
  33.   Log.logInfo(file.getLocation().toString());  
  34. }else{  
  35.   Log.logInfo("project is NOT exist");  
  36. }  


- reference :
--http://www.masatom.in/pukiwiki/Eclipse/%A5%D7%A5%E9%A5%B0%A5%A4%A5%F3%B3%AB%C8%AF%A4%CETIPS%BD%B8/%A5%EF%A1%BC%A5%AF%A5%B9%A5%DA%A1%BC%A5%B9%A4%CE%A5%EA%A5%BD%A1%BC%A5%B9%A4%F2%BC%E8%A4%EA%B0%B7%A4%A6/

0 件のコメント:

コメントを投稿