2015-10-18 238 views
1

我想試試oobjloader。 (免費波形3D格式加載器)我加載了第一個.obj,但沒有找到原始目錄。 (或只是沒有找到該文件)如何在android中獲取原始文件或原始目錄?

  Uri url = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.cube1); 
      String filename = url.toString(); 

      try { 
       Build builder = new Build(); 
       Parse obj = new Parse(builder, filename); 
      } catch (java.io.FileNotFoundException e) { 
       System.out.println("trace FileNotFoundException loading file " + filename + ", e=" + e); 
       e.printStackTrace(); 
      } catch (java.io.IOException e) { 
       System.out.println("trace IOException loading file " + filename + ", e=" + e); 
       e.printStackTrace(); 
      } 

如何獲得原始文件目錄url?

錯誤:

10-18 22:10:42.714 6136-6136/com.solar.asc.solar I/System.out﹕ trace FileNotFoundException loading file android.resource://com.solar.asc.solar/2131099648, e=java.io.FileNotFoundException: /android.resource:/com.solar.asc.solar/2131099648: open failed: ENOENT (No such file or directory) 
    10-18 22:10:42.714 6136-6136/com.solar.asc.solar W/System.err﹕ java.io.FileNotFoundException: /android.resource:/com.solar.asc.solar/2131099648: open failed: ENOENT (No such file or directory) 
    10-18 22:10:42.714 6136-6136/com.solar.asc.solar W/System.err﹕ at libcore.io.IoBridge.open(IoBridge.java:416) 
    10-18 22:10:42.714 6136-6136/com.solar.asc.solar W/System.err﹕ at java.io.FileInputStream.<init>(FileInputStream.java:78) 

我也試過其他格式,但沒有幫助。

"android.resource://" + getPackageName() + "/raw/cube1" 
"android.resource://" + getPackageName() + "/raw/cube1.obj" 

Thx all answare。

回答

0
If wanna use the cube1.obj file from raw, you can do it this way 

     InputStream in = null; 
     OutputStream out = null; 
     File outFile = null; 
     try 
     { 
      in = context.getResources().openRawResource(R.raw.cube1); 
      outFile = new File(<path where you are going to store this raw file>, <what will be name of file>); 
      out = new FileOutputStream(outFile); 
      byte[] buffer = new byte[BBConstants.KILO_VALUE]; 
      int read; 
      while((read = in.read(buffer)) != -1) 
      { 
       out.write(buffer, 0, read); 
      } 
     } 
    } 
    catch(IOException e) 
    { 

    } 

現在outFile將包含您的cube1.obj數據,您可以在要使用的位置使用它。

+0

Thx,答案,但我不想要.obj內容。我想要資源原始文件網址或原始目錄網址。我會給文件的url外部庫。 (oobjloader)只是沒有找到該文件。 – Cipo

+0

我想你會得到uri文件:/// android_res/raw/你可以試試這個。 – dex

+0

沒有幫助。但是,thx。也許我應該找資產。 – Cipo