Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法创建用于写入的文件";联想IdeaTab“;_Android_File_Fwrite - Fatal编程技术网

Android 无法创建用于写入的文件";联想IdeaTab“;

Android 无法创建用于写入的文件";联想IdeaTab“;,android,file,fwrite,Android,File,Fwrite,该应用程序将每秒在文件中写入一些数据。这在其他选项卡和手机中也可以使用,但在“Lenovo IdeaTab”(4.1)中,可以创建目录,但无法创建要写入的文件 下面是我在文件中编写的代码: public void writeDataInFile(String dataString) { File logFile = null; try { File folder = new File(Environment.getExternalStorageDirectory() + "

该应用程序将每秒在文件中写入一些数据。这在其他选项卡和手机中也可以使用,但在“Lenovo IdeaTab”(4.1)中,可以创建目录,但无法创建要写入的文件

下面是我在文件中编写的代码:

public void writeDataInFile(String dataString)
{       File logFile = null;
try {

    File folder = new File(Environment.getExternalStorageDirectory() + "/file_name_xyz");
    boolean success = true;
    if (!folder.exists()) {
        success = folder.mkdir();
    }
    if (success) {
        // Do something on success
        String file_path = folder+"/"+currentFileName+".txt";

        logFile = new File(file_path);
        if (!logFile.exists())
        {
            try
            {
                logFile.createNewFile();

                //BufferedWriter for performance, true to set append to file flag
                BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
                buf.append("\nxyz: \n");
                buf.newLine();
                buf.close();

            } 
            catch (IOException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else {
        // Do something else on failure 
        Toast.makeText(getApplicationContext(), "Failed to write", Toast.LENGTH_SHORT).show();
    }


    try
    {
        //BufferedWriter for performance, true to set append to file flag
        BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
        buf.append(dataString);
        buf.newLine();
        buf.close();
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

} catch (Exception e) {
    e.printStackTrace();
}

//Write internal storage -- data/data/xyzzz
try {
    FileOutputStream fos = openFileOutput(currentFileName, Context.MODE_APPEND);
    fos.write(dataString.getBytes());
    fos.close();

} catch (Exception e) {
    Toast.makeText(getBaseContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
}

验证平板电脑上安装了哪个版本的Android,然后在该版本的Android文档中查找文件IO API。我敢肯定,在访问某些更高版本的API中的文件时,他们改变了一些事情