JAVA Eclipse RCP幾點內容

來源:互聯網
上載者:User

自訂WORKSPACE的路徑:

 configuration\config.ini  osgi.instance.area.default=@user.home/workspace

Eclipse 程式介面美化技術

http://www.ibm.com/developerworks/cn/opensource/os-cn-ecl-rcprich/

 

JAVA按指定編碼讀寫檔案

 

 ArrayList<String> nameArr=new ArrayList();
  StringBuilder builder=new StringBuilder();
  try {
 String txtPath="C:\\地名2.txt";
    String txtNewPath="C:\\地名3.txt";
   BufferedReader reader = new BufferedReader(new InputStreamReader(
     new FileInputStream(txtPath), "GBK"));
   String line = null;
   boolean first = true;
   while ((line = reader.readLine()) != null) {
    String[] names=line.split(" ");
    for (String name : names) {
     if(name.length()>2)
     {
      
      name=name.replace("市轄區", "").replace("自治縣", "");
      name=name.replace("自治區", "");
      name=name.replace("縣", "");
      name=name.replace("省", "");
      if(name.indexOf("市")>0)
      {
      String[] newNames=name.split("市");
      if(newNames==null)
       continue;
      if(newNames.length==1)
       name=newNames[0];
       else
        name=newNames[1]; 
      }
     }
     if(nameArr.indexOf(name)==-1)
     {
     nameArr.add(name);
     builder.append(name+"\r\n");
     }
    }
   }
   reader.close();
   BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(
     new FileOutputStream(txtNewPath), "GBK"));
   writer.write(builder.toString());
   writer.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }

JAVA RCP開發 擷取應用程式WORKSPACE下檔案

 /**
  * 擷取資料庫路徑
  * @return
  */
 public static String getDB() {
  Location instanceLocation = Platform.getInstanceLocation();
  URL path = instanceLocation.getURL();

  String strPath = path.getPath() + "GS.db";
  return strPath;
 }

 

擷取RCP應用程式的啟動運行路徑

 

  File bundleFile=null;
  try {
   bundleFile = FileLocator.getBundleFile(Activator.getDefault().getBundle());
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  if(bundleFile==null)
   return null;
  File geosearchFolder = bundleFile.getAbsoluteFile();
  String geoSearchDisk= geosearchFolder.getParent();

 

根據VIEW ID擷取相應的VIEW對象

   String viewID="com.geocompass.geosearch.views.filejudger";
   IViewPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(viewID);
   FileJudgerView judgeView=(FileJudgerView)part;
   judgeView.reloadData();

 

 

JAVA開啟檔案夾方式:

 

java.awt.Desktop.getDesktop().open(new File("D:\\Java"));  

 

刪除檔案夾以及檔案夾內容

public void deleteFile(File targetFile)
{
  if(targetFile.isDirectory())
  {
   File[] list = targetFile.listFiles();
   for (int i = 0; i < list.length; i++) {
    deleteFile(list[i]);
   }
   //
   targetFile.deleteOnExit();
  }
  else
   targetFile.deleteOnExit();
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.