如何创建应用程序“保存应用程序中的文件,但不能访问另一个应用程序到我的文件”?
问题描述:
我有下面的代码:如何创建应用程序“保存应用程序中的文件,但不能访问另一个应用程序到我的文件”?
InputStream input=null;
OutputStream output=null;
HttpURLConnection connection=null;
try{
URL url=new URL(strings[0]);
connection= (HttpURLConnection) url.openConnection();
connection.connect();
int filelen=connection.getContentLength();
input=connection.getInputStream();
filechache();
output=new FileOutputStream(android.os.Environment.getExternalStorageDirectory()+"/nikandroid/"
+strings[1]+".mp3");
byte data[]=new byte[4096];
long total=0;
int count;
while((count=input.read(data))!=-1){
total+=count;
if (filelen>0) publishProgress((int)(total*100/filelen));
output.write(data,0,count);
}
}catch (Exception e){
e.printStackTrace();
}finally {
try{
if (output!=null) output.close();
if (input!=null) input.close();
}catch (IOException e){
e.printStackTrace();
}
if (connection!=null) connection.disconnect();
}
return null;
答
每个应用程序都在内部存储的私人目录。此目录的内容只能由应用读取和写入。该目录是
/data/data/<yourPackageName>
您可以将您的应用程序目录中访问各种专门的目录,如这样:/data/data/<yourPackageName>/cache
可能有类似的目录上
-
context.getFilesDir()
回报/data/data/<yourPackageName>/files
-
context.getCacheDir()
回报外部/共享内部存储,但这超出了问题的范围灰。
将其存储在应用程序的对象DB中,或者如果未使用,则隐藏文件。 – LenglBoy
您忘记了问题 – Zoe
将其保存在数据库中 – abcOfJavaAndCPP