フォルダを作成し、ファイルを作成するJava

方法と結果

 

 

 

 説明:

1つのフォルダ

  (。file.getParentFileは())(存在する {//がいる場合) フォルダが存在するか否かを判断
            するSystem.out.printlnは( "フォルダが存在!!");
        }他{
            System.out.printlnは(「フォルダが存在しませんの! !「);    
            file.getParentFile()mkdirs();. // MKDIR();ディレクトリを作成します
        }

2ファイル

  (file.exists()){//もしファイルが存在して決定
            するSystem.out.println( "本!!");
        }他{
            するSystem.out.println( "不在を!!");    
            試み{
                file.createNewFile ();
            }キャッチ(IOExceptionをE){
                するSystem.out.println( "作成に失敗しました");
                e.printStackTrace();
            }
        }

3判定ファイル属性 

  isDirectory()オブジェクトがフォルダであるかどうかをチェックします。

@GF

おすすめ

転載: www.cnblogs.com/gwf2020/p/12334264.html