導航:首頁 > 操作系統 > android獲取raw路徑

android獲取raw路徑

發布時間:2023-05-31 20:58:29

android下怎麼獲取res資源文件夾的路徑

android無法獲取res資源文件夾路徑,只能通過系統提供的封裝早凱函數訪問。
資源文件夾有:
/res/drawable
,通過getresources()訪問
/陸李喚res/values
,通過getresources()訪問
/res/layout,通過getresources()訪問
/res/xml,通過getresources()訪問
/res/raw,通過getresources()訪問
/assets,通過getassets()訪問擾弊

㈡ android studio videoview播放路徑設置

path 獲取路徑視頻文件夾寫raw文件夾
/**
* raw文件夾文件處理工具類
*
* */
public class RawFileUtils {
private RawFileUtils( ){

}

/**
* 讀取raw文件夾文件
* @param resourceId raw文件夾文件資源ID
* @return 文件內容
*
* */
public static String readFileFromRaw(Context context, int resourceId) {
if( null == context || resourceId < 0 ){
return null;
}

String result = null;
try {
InputStream inputStream = context.getResources().openRawResource( resourceId );
// 獲取文件位元組數
int length = inputStream.available();
// 創建byte數組
byte[] buffer = new byte[length];
// 文件數據讀byte數組
inputStream.read(buffer);
result = EncodingUtils.getString(buffer, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}

return result;
}
}

path=RawFileUtils.readFileFromRaw(mContext, resourceId );

㈢ android 如何批量獲取raw文件夾中的文件

HER

㈣ Android項目中res文件夾下沒有raw文件夾,且在res文件夾下新建raw文件夾後仍然有問題

親,你R文件導的android.R吧,換成com.liri.asmhelper.R

㈤ android工程res目錄下raw文件夾中的文件絕對路徑是什麼

raw是程序包里的文件,安裝到程序以後也沒有絕對路徑,因為這個是在程序內部的
但是你可以通過 InputStream is =getResources().openRawResource(R.id.filename);
來得到這個inputStream

㈥ Android開發過程中遇到的問題。關於res目錄下raw中的txt文件引用問題

InputStream is = getResources().openRawResource(R.id.fileNameID) ;
//R.id.fileNameID為需要訪問的文件對應的資源ID.接著我們就可以通過輸入流來讀取相應文件的內容了。

你這個R.raw.sgyy只是一個生成的id值,不是路徑。需要通過android提供的方法來打開具體的資源內容。

㈦ android開發,把工程目錄裡面raw目錄下的幾張照片存放到SD卡裡面去。

java">//name要創建的文件的名字,id是raw那個文件的id,R.raw.xxx就可以了
publicvoidcreateFile(Stringname,intid){
StringfilePath=ConstantPool.EXP_MUSIC+"/"+name;//文件路徑
try{
Filedir=newFile(ConstantPool.EXP_MUSIC);//目錄路徑
if(!dir.exists()){//如果不存在,則創建路徑名
System.out.println("要存儲的目錄不存在");
if(dir.mkdirs()){//創建該路徑名,返回true則表示創建成功
System.out.println("已經創建文件存儲目錄");
}else{
System.out.println("創建目錄失敗");
}
}
//目錄存在,則將apk中raw中的需要的文檔復制到該目錄下
Filefile=newFile(filePath);
if(!file.exists()){//文件不存在
System.out.println("要打開的文件不存在");
InputStreamins=context.getResources().openRawResource(
id);//通過raw得到數據資源
System.out.println("開始讀入");
FileOutputStreamfos=newFileOutputStream(file);
System.out.println("開始寫出");
byte[]buffer=newbyte[8192];
intcount=0;//循環寫出
while((count=ins.read(buffer))>0){
fos.write(buffer,0,count);
}
System.out.println("已經創建該文件");
fos.close();//關閉流
ins.close();
}
}catch(Exceptione){
e.printStackTrace();
}
}

閱讀全文

與android獲取raw路徑相關的資料

熱點內容
android仿ios時間選擇器 瀏覽:378
見識pdf 瀏覽:82
男孩子慰菊手冊pdf 瀏覽:532
注冊表啟動項命令 瀏覽:109
89c51單片機定時器 瀏覽:687
一般不適合做程序員的適合做啥 瀏覽:923
點在多邊形內演算法 瀏覽:494
程序員下班急忙回家 瀏覽:359
安慶php全套源碼交友類型網站源碼 瀏覽:92
浪潮伺服器公司地址 瀏覽:733
密約聊天交友app怎麼賺錢 瀏覽:280
滴滴java 瀏覽:109
phpexpires 瀏覽:218
matlab編程用什麼語言 瀏覽:70
php查找字元是否存在 瀏覽:701
可編程函數發生器 瀏覽:881
單片機正極接地視頻 瀏覽:67
利用python爬火車票 瀏覽:375
androidaidl如何工作 瀏覽:855
第三胸椎壓縮骨折什麼症狀 瀏覽:506