在file.createNewFile上收到错误

时间:2017-05-18 13:47:07

标签: android

我正在尝试创建该文件,如果它不存在,但我一直收到错误"没有这样的文件或目录"。我知道我已经创建了目录,因为我看到了消息"制作了目录"。请帮忙吗?

Path = Environment.getExternalStorageDirectory().getPath().toString()+ 
"/Sheridan_ips/Documents";
  FPath = new File(Path);
  if (!FPath.exists()) {
      if (!FPath.mkdirs()) {
          FPath.mkdirs();
          Log.d("MainActivity", "Made the directory");
      }
  }

  Log.d("MainActivity", "Created the directory");
  try {
      file = new File(FPath, "RSSI.txt");
      Log.d("MainActivity", "After file instantiation");
       if(!file.exists())
       {
           Log.d("MainActivity", "Before file.createNewFile");
           file.createNewFile();
           Log.d("MainActivity", "Created new file");

       }
       Log.d("MainActivity", "Before PrintWriter");
       pw = new PrintWriter(new FileWriter(file), true);
       Log.d("MainActivity", "After PrintWriter");
       pw.print(beacon.getRssi());
       pw.print(kalman.kalman(rssis));
       pw.println();
       pw.close();
   } catch (FileNotFoundException e) {
       e.printStackTrace();
   } catch (IOException e) {
       e.printStackTrace();
   }
}

0 个答案:

没有答案