2015-10-18 243 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