文件文件; FileOutputStream fileOutputStream;
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); final List pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0); for (Object obj : pkgAppsList) { ResolveInfo resolveInfo = (ResolveInfo) obj; PackageInfo packageInfo = null; try { file = new File(Environment.getExternalStorageDirectory(),"MyResearchFile.txt"); FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos); packageInfo = getPackageManager().getPackageInfo(resolveInfo.activityInfo.packageName, PackageManager.GET_PERMISSIONS); String[] requestedPermissions = packageInfo.requestedPermissions; final PackageManager pm = getApplicationContext().getPackageManager(); ApplicationInfo ai; ai = pm.getApplicationInfo(resolveInfo.activityInfo.packageName,0); final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "unknown"); for (int i = 0,j=0; i < requestedPermissions.length; i++,j++) { if(requestedPermissions[i].contains("READ_CONTACTS") ) { outputStreamWriter.append((applicationName + " requested " + requestedPermissions[i]).toString()); } if(requestedPermissions[i].contains("WRITE_CONTACTS")) { outputStreamWriter.append((applicationName + " requested " + requestedPermissions[i]).toString()); } } outputStreamWriter.flush(); outputStreamWriter.close();
问题:追加功能不是将文本追加到文本文件中.我正在开发一个Android应用程序,它将所有权限详细信息写入文本文件.
使用带有append标志的构造函数
FileOutputStream fos = new FileOutputStream(file, true);