我正在某个应用程序上工作,在该应用程序中我必须从某些http位置更新资产/原始文件夹运行时中存在的某些文件。
任何人都可以通过共享如何在资产或原始文件夹中写入文件来帮助我吗?
Answers:
无法完成。是不可能的。
为什么不更新本地文件系统上的文件呢?您可以将文件读/写到应用程序沙箱区域。
http://developer.android.com/guide/topics/data/data-storage.html#files内部
您可能要研究的其他替代方法是“共享参考”和使用“缓存文件”(所有信息都在上面的链接中进行了介绍)
您无法将数据写入资产/原始文件夹,因为它是打包的(.apk)并且大小不可扩展。
如果您的应用程序需要从服务器下载依赖项文件,则可以使用android(http://developer.android.com/guide/market/expansion-files.html)提供的APK扩展文件。
针对同一问题的另一种方法可能会帮助您在应用程序的专用上下文中读取和写入文件
String NOTE = "note.txt";
private void writeToFile() {
try {
OutputStreamWriter out = new OutputStreamWriter(openFileOutput(
NOTES, 0));
out.write("testing");
out.close();
}
catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), 2000).show();
}
}
private void ReadFromFile()
{
try {
InputStream in = openFileInput(NOTES);
if (in != null) {
InputStreamReader tmp = new InputStreamReader(in);
BufferedReader reader = new BufferedReader(tmp);
String str;
StringBuffer buf = new StringBuffer();
while ((str = reader.readLine()) != null) {
buf.append(str + "\n");
}
in.close();
String temp = "Not Working";
temp = buf.toString();
Toast.makeText(this, temp, Toast.LENGTH_SHORT).show();
}
} catch (java.io.FileNotFoundException e) {
// that's OK, we probably haven't created it yet
} catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), 2000).show();
}
}