Article View: borland.public.jbuilder.java.language
Article #7694Re: cannot create a new file with identical name to an existing folder in the same path
From: Torsten Welches
Date: Mon, 28 May 2001 07:25
Date: Mon, 28 May 2001 07:25
50 lines
2107 bytes
2107 bytes
Yonatan,
you need two File instances, one representing the directory,
the other representing the file:
File path = new File("d://pd_projects");
path.mkdir();
File file = new File("d://pd_projects//test");
file.createNewFile();
Torsten
"Yonatan Taub" <taubu@tms.huji.ac.il> wrote:
>The following short program:
>===================
>
>import java.io.*;
>
>public class CreateFile {
> public static void main(String[] args) throws Exception {
>
> String path = "d:\\pd_projects\\test";
> File file = new File(path);
>
> file.mkdir();
> file.createNewFile();
> }
>}
>
>
>produces an exception:
>===============
>
>java.io.IOException: Access is denied
> at java.io.Win32FileSystem.createFileExclusively(Native Method)
> at java.io.File.createNewFile(File.java:693)
> at CreateFile.main(CreateFile.java:10)
>Exception in thread "main"
>
>
>
>If I re-order the code so that the file will be created before the
>directory, the file is created but the directory does not and no exception
>is thrown.
>
>
>Can anyone help me on this?
>
>
Technical Details
Message-ID:
<3b11fd6e$1_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!141.201.2.63!newshunter!cosy.sbg.ac.at!newsrouter.chello.at!amsnews01.chello.com!newsfeed.freenet.de!fu-berlin.de!news.boerde.de!dnewsReferences:
<3b115fe8$2_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,918686e0c4316985 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-05-28 00:48:14 PST From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Subject: Re: cannot create a new file with identical name to an existing folder in the same path Newsgroups: borland.public.jbuilder.java.language X-User-Info: 193.158.55.74 193.158.55.74 References: <3b115fe8$2_1@dnews> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3b11fd6e$1_2@dnews> Date: 28 May 2001 00:25:34 -0700 X-Trace: dnews 991034734 207.105.83.65 (28 May 2001 00:25:34 -0700) Lines: 51 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!141.201.2.63!newshunter!cosy.sbg.ac.at!newsrouter.chello.at!amsnews01.chello.com!newsfeed.freenet.de!fu-berlin.de!news.boerde.de!dnews