public static File createNewFile(String filePath)

 public static File createNewFile(String filePath) {
  if (filePath == null)
   return null;
  File newFile = new File(filePath);
  try {
   if (!newFile.exists()) {
    int slash = filePath.lastIndexOf('/');
    if (slash > 0 && slash < filePath.length() - 1) {
     String dirPath = filePath.substring(0, slash);
     File destDir = new File(dirPath);
     if (!destDir.exists()) {
      destDir.mkdirs();
     }
    }
   } else {
    newFile.delete();
   }
   newFile.createNewFile();
  } catch (IOException e) {
   return null;
  }
  return newFile;
    }

你可能感兴趣的:(String,File,null)