当前位置:  开发笔记 > 编程语言 > 正文

OutputStreamWriter.append不将文本附加到Android编程的文本文件中

如何解决《OutputStreamWriter.append不将文本附加到Android编程的文本文件中》经验,为你挑选了1个好方法。

文件文件; 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应用程序,它将所有权限详细信息写入文本文件.



1> Reimeus..:

使用带有append标志的构造函数

FileOutputStream fos = new FileOutputStream(file, true);

推荐阅读
手机用户2502852037
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有