안드로이드 개발 질문/답변
(글 수 45,052)
안녕하세요. ^^;;앱 개발에 앞서 제목과 마찬가지로 질문이 있습니다.android 2.x 대 버전에서는 위와 같이 /data/data/[자기 패키지명]/files에 데이터를 저장해서 앱에서 불러오게끔 하는게 되었는데 4.0.3버전의 갤노트에서 같은 소스를 돌리니 데이터 저장이 안되서요;;
소스코드는 다음과 같습니다.
new DownloadFileFromURL().execute(SN.getInputStringFromUrl("SN.connectURL),
this.getApplicationInfo().sourceDir+"/files/test.db");
아래의 소스를 위와 같이 불러옵니다.;
protected String doInBackground(String... DataURL) {
int count;
try {
Log.i("test progress",DataURL[0]);
URL url = new URL("DataURL[0]);
URLConnection conection = url.openConnection();
conection.connect();
// this will be useful so that you can show a tipical 0-100% progress bar
int lenghtOfFile = conection.getContentLength();
Log.i("test FileOutput",DataURL[1] ); // download the file
InputStream input = new BufferedInputStream(url.openStream());
Log.i("test fileinput","input..");
// Output stream
OutputStream output = new FileOutputStream(DataURL[1]);
Log.i("test fileinput","input..2");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count; publishProgress(""+(int)((total*100)/lenghtOfFile));
// writing data to file
output.write(data, 0, count);
}
Log.i("test total",total+"");
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
} 



logcat에는 Log.i(
"test fileinput","input..");는 찍히는데 Log.i("test fileinput","input..2"); 는 안찍힙니다. OutputStream output =newFileOutputStream(DataURL[1]); 때문이라면 DataURL[1]이 잘못되서 저장이 안되나..하는 생각이 들기도 하고..정 안되면 /mnt/sdcard/..에 저장해야겠지만 저 경로가 마음에 들어서요;;