天秀lllj
本帖最后由 天秀lllj 于 2020-9-5 14:40 编辑

代码是if (!(new file("./Load/NewPlayer/" + p.getName() + ".yml").exists())) {
  (new file("./Load/NewPlayer/" + p.getName() + ".yml").exists());
}
(帮我康康呗,大佬)

洞穴夜莺
本帖最后由 洞穴夜莺 于 2020-9-5 14:41 编辑

使用File#createNewFile(),下面是该方法原文
  1. /**
  2.      * Atomically creates a new, empty file named by this abstract pathname if
  3.      * and only if a file with this name does not yet exist.  The check for the
  4.      * existence of the file and the creation of the file if it does not exist
  5.      * are a single operation that is atomic with respect to all other
  6.      * filesystem activities that might affect the file.
  7.      * <P>
  8.      * Note: this method should <i>not</i> be used for file-locking, as
  9.      * the resulting protocol cannot be made to work reliably. The
  10.      * {@link java.nio.channels.FileLock FileLock}
  11.      * facility should be used instead.
  12.      *
  13.      * @Return <code>true</code> if the named file does not exist and was
  14.      *          successfully created; <code>false</code> if the named file
  15.      *          already exists
  16.      *
  17.      * @throws  IOException
  18.      *          If an I/O error occurred
  19.      *
  20.      * @throws  SecurityException
  21.      *          If a security manager exists and its {@link
  22.      *          java.lang.SecurityManager#checkWrite(java.lang.String)}
  23.      *          method denies write access to the file
  24.      *
  25.      * @Since 1.2
  26.      */
  27.     public boolean createNewFile() throws IOException {
  28.         SecurityManager security = System.getSecurityManager();
  29.         if (security != null) security.checkWrite(path);
  30.         if (isInvalid()) {
  31.             throw new IOException("Invalid file path");
  32.         }
  33.         return fs.createFileExclusively(path);
  34.     }
复制代码

天秀lllj
洞穴夜莺 发表于 2020-9-5 14:39
使用File#createNewFile(),下面是该方法原文

我一般创建config.yml的话是File file = new file("config.yml")...

第一页 上一页 下一页 最后一页