如何在android中获取原始文件或原始目录?

如何在android中获取原始文件或原始目录?,android,file,resourcedictionary,Android,File,Resourcedictionary,我想试试看。(FreeWave3D格式加载程序)我加载了第一个.obj,但没有找到原始目录。(或者只是没有找到文件) 如何获取原始文件目录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.F

我想试试看。(FreeWave3D格式加载程序)我加载了第一个.obj,但没有找到原始目录。(或者只是没有找到文件)

如何获取原始文件目录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)
Thx all answare。

如果要使用raw中的cube1.obj文件,可以这样做
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) 
    {

    } 
InputStream in=null; OutputStream out=null; 文件outFile=null; 尝试 { in=context.getResources().openRawResource(R.raw.cube1); outFile=新文件(,); out=新文件输出流(输出文件); 字节[]缓冲区=新字节[BBConstants.KILO_值]; int-read; while((read=in.read(buffer))!=-1) { 输出。写入(缓冲区,0,读取); } } } 捕获(IOE异常) { }
现在,outFile将包含您的cube1.obj数据,您可以在您想使用的地方使用它。

如果您想从raw使用cube1.obj文件,可以这样做
InputStream in=null;
OutputStream out=null;
文件outFile=null;
尝试
{
in=context.getResources().openRawResource(R.raw.cube1);
outFile=新文件(,);
out=新文件输出流(输出文件);
字节[]缓冲区=新字节[BBConstants.KILO_值];
int-read;
while((read=in.read(buffer))!=-1)
{
输出。写入(缓冲区,0,读取);
}
}
} 
捕获(IOE异常)
{
} 

现在outFile将包含您的cube1.obj数据,您可以在您想使用的地方使用它。

Thx,答案,但我不想要.obj内容。我想要资源原始文件url或原始目录url。我将把文件url提供给外部库。(oobjloader)只是找不到文件。我猜您得到的uri为file:///android_res/raw/ 你能试试这个.Thx,答案,但我不想要.obj内容。我想要资源原始文件url或原始目录url。我将把文件url提供给外部库。(oobjloader)只是找不到文件。我猜您得到的uri为file:///android_res/raw/ 你能试试这个吗。
"android.resource://" + getPackageName() + "/raw/cube1"
"android.resource://" + getPackageName() + "/raw/cube1.obj"
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) 
    {

    }