我正在尝试为我创建的文件分配权限,该文件用于设置系统设置。我在线上获得Io异常
inputStream=context.getAssets().open(fileName);
在我的清单文件中,我已使用
分配了文件权限<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
允许读取和写入系统设置文件。但仍然是Exception.Thanks提前。 根据请求,我将添加错误发生的代码
public boolean copyConfigFile(String fileName) throws IOException {
File configFile = new File(systemDir, fileName);
Log.d(getClass().getSimpleName(), "Config file path :" + configFile.getAbsolutePath());
Log.d(getClass().getSimpleName(), "FILE NAME::" + fileName);
if(!configFile.exists()){
configFile.createNewFile();
InputStream is = null;
OutputStream os = null;
try {
is = ctx.getAssets().open(fileName);
os = new FileOutputStream(configFile);
byte []fileBytes = new byte[is.available()];
is.read(fileBytes);
os.write(fileBytes);
Log.d(getClass().getSimpleName(), "File copied.");
return true;
} finally {
if(is != null){
is.close();
}
if(os != null){
os.close();
}
}
}else{
Log.d(getClass().getSimpleName(), "File already exist.");
return true;
}
}
答案 0 :(得分:1)
嗯..发现错误。创建的系统设置文件应该保存在资产目录中,而不是保存在任何地方Else.I是一个愚蠢的,不能事先读取它
答案 1 :(得分:0)
你试过WRITE_SECURE_SETTINGS吗?
或者可能是文件路径错误。您可能需要发布更具体的代码。