1 2 Previous Next 18 Replies Latest reply: Aug 24, 2007 4:29 PM by 807605 RSS

    IO Exception ???

    807605
      Hi,
      Can somebody explain what does this IO error mean and why should I get this error?
      java.io.IOException: Not a directory
      at java.io.File.createNewFile(File.java:876)
      at web.SpiderMulti.create(SpiderMulti.java:606)
      at web.SpiderMulti.add(SpiderMulti.java:581)
      at web.URLAnalizer.findLinks(URLAnalizer.java:187)
      at web.URLAnalizer.download(URLAnalizer.java:140)
      at web.URLAnalizer.run(URLAnalizer.java:79)
      I am getting this error on the line like;
      new File(fileName).createNewFile();

      Thanks for all help.
        • 1. Re: IO Exception ???
          807605
          You are trying to perform an operation on a Directory - but your Directory is not a Directory. Pretty self explanatory. Why don't you post the code that is causing the error.
          • 2. Re: IO Exception ???
            807605
            Hi,

            Thanks for explanation but I have used the same code on a different eclipse with the same file creation and it didn't give any errors.

            The code is:
            import java.io.File;
            import java.io.IOException;
            
            
            public class Deneme 
            {
                 
                 
                 public Deneme()
                 {
                      create(new File("/home/kmuslu/Results/tt.wikipedia.org/wiki/T%25C3%25B6rkem%3A%25C4%259E%25C3%25A4il%25C3%25A4"));
                 }
                 
                 private void create(File f) 
                 {
                      String [] all = f.getAbsolutePath().split("/");
                      
                      String current = "";
                      for (int a = 0; a < all.length - 1; a++)
                      {
                           current += all[a];
                           File temp = new File(current);
                           if (!temp.exists())
                           {
                                temp.mkdir();
                           }
                           current += "/";
                      }
                      current += all[all.length-1];
                      File temp = new File(current);
                      if (!temp.exists())
                      {
                           try {
                                temp.createNewFile();
                           } catch (IOException e) {
                                System.out.println("File creation failed @ " + temp.getAbsolutePath());
                                e.printStackTrace();
                           }
                      }
                 }
                 
                 public static void main(String [] args)
                 {
                      new Deneme();
                 }
            
            }
            The purpose is to create any given fileName blankly on the harddisk.
            Thanks...
            • 3. Re: IO Exception ???
              807605
              You can also get that error if
              a: the directory does not exist
              b: you do not have permission to create that directory (or the directory is not creatable)
              • 4. Re: IO Exception ???
                807605
                Hi,
                In the explanation if the directory doesn't exist I got a different one like no such directory. And I am pretty sure that I have the permission to write to that directory because it is always in my account "/home/kmuslu/blablabla". However what does it mean directory is not creatable?
                Also this file is in a project that uses multi-threading. Although I am using locks, can it be a multi-threaded problem?
                Thanks...
                • 5. Re: IO Exception ???
                  807605
                  Hi,
                  In the explanation if the directory doesn't exist I
                  got a different one like no such directory. And I am
                  pretty sure that I have the permission to write to
                  that directory because it is always in my account
                  "/home/kmuslu/blablabla". However what does it mean
                  directory is not creatable?
                  Also this file is in a project that uses
                  multi-threading. Although I am using locks, can it be
                  a multi-threaded problem?
                  Thanks...
                  That is a possibility.
                  • 6. Re: IO Exception ???
                    807605
                    Hi,
                    But what could be the problem? A deadlock? A datarace? Could you be more specific?
                    Thanks...
                    • 7. Re: IO Exception ???
                      807605
                      Hi,
                      But what could be the problem? A deadlock? A
                      datarace? Could you be more specific?
                      Thanks...
                      Well, seeing as how you
                      a: have permissions
                      b: know that it is a directory
                      c: are using locks

                      My guess would be a dead lock.
                      • 8. Re: IO Exception ???
                        807605
                        But there is no condition, wait, or anything that could cause that. I am sending the part that calls that function:
                        public void add(Element e)
                             {
                                  directoryLock.lock();
                                  URL temp = null;
                                  try {
                                       temp = new URL(e.getParent(),e.getName());
                                  } catch (MalformedURLException e1) {
                        //               System.err.println("name is " + e.getName() + ", parent is " + e.getParent().toString());
                                       directoryLock.unlock();
                                       return;
                                  }
                                  String fileName = SpiderMulti.changeToFileName(temp.toString());
                                  File f = new File(fileName);
                                  if (! f.exists())
                                  {
                                       create(f);     
                                  }
                                  directoryLock.unlock();
                             }
                             
                             private void create(File f) 
                             {
                                  String [] all = f.getAbsolutePath().split("/");
                                  
                                  String current = "";
                                  for (int a = 0; a < all.length - 1; a++)
                                  {
                                       current += all[a];
                                       File temp = new File(current);
                                       if (!temp.exists())
                                       {
                                            temp.mkdir();
                                       }
                                       current += "/";
                                  }
                                  current += all[all.length-1];
                                  File temp = new File(current);
                                  if (!temp.exists())
                                  {
                                       try {
                                            temp.createNewFile();
                                       } catch (IOException e) {
                                            System.out.println("File creation failed @ " + temp.getAbsolutePath());
                                            e.printStackTrace();
                                       }
                                  }
                             }
                        changeToFileName is a basic method that changs a url link to a folder name like:
                        http://www.google.com.tr ----->>>>> /home/kmuslu/Results/www.google.com.tr
                        That's the whole code.
                        • 9. Re: IO Exception ???
                          796447
                          You know you're not creating files named:
                          /home/...
                          but rather:
                          home/...
                          (note the missing slash before "home").
                          So all your paths are relative to the current directory, not at the root. I don't know if that's part of your trouble or not, but just pointing it out in case it's part of the deal.
                          • 10. Re: IO Exception ???
                            807605
                            Couldn't get the point.
                            The machine is linux based so as far as I know the root directory is "/". So home folder should be "/home". Are you trying to point out something different?
                            • 11. Re: IO Exception ???
                              796447
                              Couldn't get the point.
                              The machine is linux based so as far as I know the
                              root directory is "/". So home folder should be
                              "/home". Are you trying to point out something
                              different?
                              Yes. You're creating files like this:
                              File f = new File("home");
                              f.mkdir();
                              f = new File("home/kmuslu");
                              f.mkdir();
                              // etc
                              All of the above are relative to the current working directory. If your current working directory is at the root, then it's creating them at the root. Otherwise, it isn't.
                              • 12. Re: IO Exception ???
                                807605
                                Yes, but I am creating the files only if they are not already created. So when java looks for /home it finds it and skips it (at least I think) so the files that root should create /home and /home/kmuslu are skipped because they are already created in the system and the other files are only created or directories created if they don't exist and I do have the permission to create files under /home/kmuslu tree. Still it is possible that I didn't understand your point. So excuse me and try to explain please..
                                Thanks for all help.
                                • 13. Re: IO Exception ???
                                  796447
                                  Once again, and please pay attention this time:
                                  It is not looking for /home (note the slash in front). It is looking for "home", a relative directory from the current working directory (note NO slash in front).
                                  • 14. Re: IO Exception ???
                                    807605
                                    Hi,
                                    I have added a System.out.println() to check your suggestion however it does find the correct path.
                                    The code is:
                                    import java.io.File;
                                    import java.io.IOException;
                                    
                                    
                                    public class Deneme 
                                    {
                                         
                                         
                                         public Deneme()
                                         {
                                              create(new File("/home/kmuslu/Results/tt.wikipedia.org/wiki/T%25C3%25B6rkem%3A%25C4%259E%25C3%25A4il%25C3%25A4"));
                                         }
                                         
                                         private void create(File f) 
                                         {
                                              String [] all = f.getAbsolutePath().split("/");
                                              
                                              String current = "";
                                              for (int a = 0; a < all.length - 1; a++)
                                              {
                                                   current += all[a];
                                                   System.out.println(current);
                                                   File temp = new File(current);
                                                   if (!temp.exists())
                                                   {
                                                        temp.mkdir();
                                                   }
                                                   current += "/";
                                              }
                                              current += all[all.length-1];
                                              File temp = new File(current);
                                              if (!temp.exists())
                                              {
                                                   try {
                                                        temp.createNewFile();
                                                   } catch (IOException e) {
                                                        System.out.println("File creation failed @ " + temp.getAbsolutePath());
                                                        e.printStackTrace();
                                                   }
                                              }
                                              
                                         }
                                         
                                         public static void main(String [] args)
                                         {
                                              new Deneme();
                                         }
                                    
                                    }
                                    --------
                                    Result on the console is:

                                    /home
                                    /home/kmuslu
                                    /home/kmuslu/Results
                                    /home/kmuslu/Results/tt.wikipedia.org
                                    /home/kmuslu/Results/tt.wikipedia.org/wik
                                    So I think it is not the problem. Am I still making a mistake? Thanks...i
                                    1 2 Previous Next