2011-05-02 5 views
20

자산 폴더에서 복사하려는 전체 폴더 구조가 있습니다. 그러나 mContext.getAssets(). open()은 하나의 파일 만 복사하는 데 적합한 InputStream을 반환 할 수 있도록 파일 이름 만 필요로하는 것처럼 보입니다. 내가 필요한 것은 모든 파일과 폴더를 반복하여 복사 할 수 있도록 내 자산 폴더에있는 폴더에서 만든 파일입니다.응용 프로그램 패키지의 Android 자산 폴더 경로를 얻는 방법

File 객체를 만들 수 있도록 assets 폴더에 대한 경로를 얻는 방법을 아는 사람이 있습니까?

편집 : 일부 연구 후에는 절대 경로가있는 assets/및 raw/폴더의 파일에 액세스하여 File 객체를 만들 수없는 것으로 보입니다. 앱 패키지의 암호화와 관련이있을 것입니다. 나는 누군가가 나를 틀리게 증명할 수 있기를 바란다!

최종 편집 :에) (오픈)

private static final String[] DEFAULT_ALBUM_FILES = 
    {INTRO_TO_FLASHUM_DIR+"03 Never Can Say Goodbye.m4a", 
    INTRO_TO_FLASHUM_DIR+"11 Bossa Baroque.m4a", 
    INTRO_TO_FLASHUM_DIR+"intro fling.3gp"}; 

나는 다음이 복사를 통해 개별적으로 mContext.getAssets를 (사용하여 각 파일을 반복 :. 나는 여분의 자산 파일을 보유하는 문자열 배열을 만들어 결국 InputStream를 취득합니다. 현재 정상적인 파일 작업을 사용하여 자산의 폴더를 반복 할 수 없다고 생각합니다.

+0

당신은 무엇을 시도? 참조 : http://www.wiseandroid.com/post/2010/06/14/Android-Beginners-Intro-to-Resources-and-Assets.aspx – f20k

+0

네, 여기에 제가 한 일이 정확하게 설명되어 있습니다. – cdavidyoung

답변

3

폴더를/raw 폴더로 옮길 수 있습니까? 그럼 당신은 사용할 수 있습니다

com.your.package:raw/yourFile 
이 같이

: 여기

int resourceId = context.getResources().getIdentifier("com.your.package:raw/somefile.txt"); 
File f = new File(context.getResources().openRawResource(resourceId)); 

을 그리고 누군가는 자산 폴더를하고있어 :

Android Assets with sub folders

InputStream is = getAssets().open("subfolder/somefile.txt"); 
+0

이것은 유망 해 보입니다. 나는 그것을 시험해 볼 것입니다. 나는 결과로 돌아갈 것이다. 감사! – cdavidyoung

+0

원시 폴더는 절대 경로 참조를 허용하지 않습니다. 적어도 내가 알아낼 수 없었던 ... – cdavidyoung

+0

물론 편집 됨 응답 – Blundell

-5

사용 file:///android_asset을 자산에 액세스하기위한 폴더에 저장 한 다음 하위 폴더를 항상 제공 할 수 있습니다.

AssetManager assetManager = null; // null ??? Get the AssetManager here. 
     AssetFileDescriptor assetFileDescriptor = null; 
     try{ 
      assetFileDescriptor = assetManager.openFd("file:///android_asset/yourfolder/file"); 
       FileDescriptor fd = assetFileDescriptor.getFileDescriptor(); 
     } catch (Exception e){} 
+0

"file : /// android_asset"을 사용하는 방법을 모르겠다. 이것을 "File file = new File (...);"형식으로 넣을 수 있습니까? – cdavidyoung

+0

assetmanager를 가져오고 assetfiledescriptor를 가져 와서 assetfiledescriptor에서 filedescriptor를 가져옵니다. – yogsma

+8

그런데 어떻게 FileDescriptor를 File로 변환합니까? – cdavidyoung

4
  AssetManager am = con.getAssets();//u have get assets path from this code 

     InputStream inputStream = null; 

     inputStream = am.open("file.xml"); 

또는

String file_name="ur.xml" 

inputStream = am.open("foldername/"+ur); 
+0

완벽한 답변 감사합니다. +1 –

관련 문제