java.io.IOException: Access is denied + java.io.FileNotFoundException: C:\Docume

My simple program has a wierd error :stuck_out_tongue:
java.io.IOException: Access is denied
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at bity.Main.main(Main.java:34)
java.io.FileNotFoundException: C:\Documents and Settings\HandE\My Documents (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(FileOutputStream.java:179)
at java.io.FileOutputStream.(FileOutputStream.java:131)
at bity.Main.main(Main.java:39)
I am using windows XP SP 2 and JSE JDK 1.6.0
this is my code:


package bity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 * @author HandE
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        File file = new File(System.getProperty("user.home") + File.separator + "My Documents");
        try {
            file.createNewFile();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        try {
            FileOutputStream F = new FileOutputStream (file);
            String a = "a";
            System.out.println(a);
            System.out.println(a.getBytes());
            try {
                F.write(a.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            String A = "A";
            System.out.println(A);
            System.out.println(A.getBytes());
            try {
                F.write(A.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            String b = "b";
            System.out.println(b);
            System.out.println(b.getBytes());
            try {
                F.write(b.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            String B = "B";
            System.out.println(B);
            System.out.println(B.getBytes());
            try {
                F.write(B.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            String c = "c";
            System.out.println(c);
            System.out.println(c.getBytes());
            try {
                F.write(c.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            String C = "C";
            System.out.println(C);
            System.out.println(C.getBytes());
            try {
                F.write(C.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            String d = "d";
            System.out.println(d);
            System.out.println(d.getBytes());
            try {
                F.write(d.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            String D = "D";
            System.out.println(D);
            System.out.println(D.getBytes());
            try {
                F.write(D.getBytes());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
        // TODO code application logic here
    }
    
}


why am i getting this error :โ€™( :โ€™( :โ€™( :โ€™( :โ€™( :โ€™( :โ€™( :โ€™( ???

did you check if the file doesnโ€™t already exists?

(since windows automaticly creates that directory wenn a user is createdโ€ฆ the likelyness is high ;))

opes i just rilsed i tried to write to a directory not a file :-[ :-[ :-[ :-[ :-[ :-[ :-[