我有一个关于与应用程序一起上传的文件的问题。我需要为我的公司创建一个应用程序,他们将在其中存储PDF文件(单击按钮可以下载特定文件)。我的问题是:是有可能与应用程序一起预加载文件?还是我需要服务器或其他东西来存储这些文件,并且当某人单击特定按钮时,它将向服务器请求特定文件?
是。在中创建一个新文件夹project location/app/src/main
,并将其重命名为assets
。然后在那里复制文件。
如果要在运行时复制这些文件,请使用以下方法:
private void copy(String fileName, String path) throws IOException {
AssetManager assetManager = this.getAssets();
InputStream in = assetManager.open(fileName);
try {
OutputStream out = new FileOutputStream(path);
try {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} finally {
out.close();
}
} finally {
in.close();
Log.d(TAG, "copy: successfully copied");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句