2012-07-12 1 views
0

가능한 중복 :
How to write files to assets folder or raw folder in android?어떻게 안드로이드에 자산/하위 폴더에 이미지를 저장할 수 있습니까? 자산 폴더 크기의 최대 한도가 있습니까?

어떻게 내가 안드로이드에 자산/하위 폴더에 이미지를 저장할 수 있습니까? 자산 폴더 크기의 최대 한도가 있습니까? actully 나는 웹에서 많은 이미지를 얻고 있으며 자산의 하위 폴더에있는 모든 이미지를 다운로드하려고합니까? 그것은 가능하고 어떻게? actully 내 코드는 다음과 같이, 그것의 sdcard에 이미지를 저장 -

String filepath=null; 
     try { 
     //set the download URL, a url that points to a file on the internet 
     //this is the file to be downloaded 
     URL url = new URL(Url); 
     //create the new connection 
     HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 

     //set up some things on the connection 
     urlConnection.setRequestMethod("GET"); 
     urlConnection.setDoOutput(true); 
     //and connect! 
     urlConnection.connect(); 
     //set the path where we want to save the file 
     //in this case, going to save it on the root directory of the 
     //sd card. 
    File SDCardRoot = Environment.getExternalStorageDirectory(); 
     //create a new file, specifying the path, and the filename 
     //which we want to save the file as. 

     String filename= "downloadedFile.png"; // you can download to any type of file ex:.jpeg (image) ,.txt(text file),.mp3 (audio file) 
     Log.i("Local filename:",""+filename); 
     file = new File(SDCardRoot,filename); 
     if(file.createNewFile()) 
     { 
     file.createNewFile(); 
     } 

     //this will be used to write the downloaded data into the file we created 
     FileOutputStream fileOutput = new FileOutputStream(file); 

     //this will be used in reading the data from the internet 
     InputStream inputStream = urlConnection.getInputStream(); 

     //this is the total size of the file 
     int totalSize = urlConnection.getContentLength(); 
     //variable to store total downloaded bytes 
     int downloadedSize = 0; 

     //create a buffer... 
     byte[] buffer = new byte[1024]; 
     int bufferLength = 0; //used to store a temporary size of the buffer 

     //now, read through the input buffer and write the contents to the file 
     while ((bufferLength = inputStream.read(buffer)) > 0) { 
     //add the data in the buffer to the file in the file output stream (the file on the sd card 
     fileOutput.write(buffer, 0, bufferLength); 
     //add up the size so we know how much is downloaded 
     downloadedSize += bufferLength; 
     //this is where you would do something to report the prgress, like this maybe 
     Log.i("Progress:","downloadedSize:"+downloadedSize+"totalSize:"+ totalSize) ; 

     } 
     //close the output stream when done 
     fileOutput.close(); 
     if(downloadedSize==totalSize) filepath=file.getPath(); 

     //catch some possible errors... 
     } catch (MalformedURLException e) { 
     e.printStackTrace(); 
     } catch (IOException e) { 
     filepath=null; 
     e.printStackTrace(); 
     } 
     Log.i("filepath:"," "+filepath) ; 

는 친절하게 나에게 그 몇 가지 솔루션을 제공합니다.

+0

가능한 복제본은 여기에서 설명합니다. http://stackoverflow.com/questions/3760626/how-to-write-files-to-assets-folder-or-raw-folder-in-android and http://stackoverflow.com/questions/8788519/자산에서 이미지를 저장할 수 있음 응용 프로그램에서 폴더 – Orlymee

답변

0

당신은 자산 폴더에 이미지를 저장하지 못했습니다시키는 문제

그것의 읽기 전용을 자산 폴더에 대한

그리고 일반적으로 MAX의 크기는 각 파일에 대한 1MB입니다

당신은 이미지를 저장할 수 있습니다 sdcard에.

+0

최대 크기는 더 이상 ** 1MB ** 큰 파일 크기를 가질 수 있습니다. –

+0

숨어서 무엇을 의미합니까? 기기에 저장하는 항목은 전적으로 안전 할 수 있지만 내부 저장소로 충분할 수 있습니다. http://developer.android.com/guide/topics/data/data-storage.html#filesInternal? – Estel

+0

귀중한 의견과 찬사를 보내 주셔서 감사합니다. 이제 모든 이미지를 sdcard의 하위 폴더에 저장합니다. –

관련 문제