String path="c://aa/temp.txt";
File f2=new File(path);
File aa=f2.getParentFile();
aa.mkdirs();
f2.createNewFile();

解决方案 »

  1.   

    我是说如果在c:下存在一个名为aa的文件。它就不能再建一个名为aa的目录。如果不存在这个文件,是可以建立这个目录的。
      

  2.   

    procedure TForm1.Button8Click(Sender: TObject);
    var
      path:string;
      filename:string;
    begin
    path:=ExtractFilePath(Application.ExeName)+'report\'+edit1.Text;
    filename:=edit1.Text;
    if searchfolder(filename) then
    begin
    showmessage('该文件夹已经存在');
    end
    else
    begin
    showmessage('文件夹不存在');
    ForceDirectories(path);
    end;end;
    function  Tform1.searchfolder(var foldername:string):boolean;
    var
      path:string;
      sr: TSearchRec;
    begin
    path:=ExtractFilePath(Application.ExeName)+'report\'+foldername;
      if FindFirst(path, faAnyFile, sr) = 0 then
        begin
        if ((sr.Attr and fadirectory) = fadirectory) and (sr.Name<>'.') and (sr.Name<>'..') then
         begin
           result:=true;
         end;
         end //first
         else
         result:=false;
        FindClose(SR);
    end;
      

  3.   

    file=new File("c:\\study\\");
                if(!passFile.exists())
                  {
                    passFile.mkdir();
                  }
                passFile=new File("c:\\winnt\\file.txt");楼主顺便问一句String path="c://aa/temp.txt";
    你用的不是WINDOWS?这个路径是在WINDOWS下的话,如何能通过?
      

  4.   

    "c:/aa/temp.text"用的是java标准格式,无论windows/unix/mac都可行
      

  5.   

    如果c:下存在名为study这个文件就不能创建study这个目录。