7 Replies Latest reply on Jun 5, 2008 1:27 PM by 807591

    java.io.FileNotFoundException...help

    807591
      hi im trying to save a file..
      the path of the file is D:\objectFiles
      and the name of the file depends on the user parameters

      if the user is trying to access a url of our site..he will define some values in the query string
      if the url is something like
      http://www.abc.com/query?id=123&firstname=John&lastname=Smith
      then the name of the file would be 123_John_Smith.txt

      so the whole path is D:\objectFiles\123_John_Smith.txt

      but in my log..i see an exception which says

      java.io.FileNotFoundException: D:\objectFiles\123_John_
      Smith.txt: The filename, directory name, or volume label syntax is incorrect

      I dont know why I am getting that new line after John_

      I tried to enter a last name as something like '\nSmith', then it gives me an error saying D:\objectFiles\123_Jphn_\nSmith: System cannot find the path specified..

      Any ideas on how could I get the first exception?

      Please help me!!!!

      Edited by: hari786 on Jun 4, 2008 12:28 PM

      Edited by: hari786 on Jun 4, 2008 12:29 PM
        • 1. Re: java.io.FileNotFoundException...help
          807591
          import java.io.*;
          
          public class IOTest {
              public static void main(String[] args) throws IOException {
                  File file = new File("123_John_\nSmith.txt");
                  FileOutputStream out = new FileOutputStream(file);
                  out.close();
          
              }
          }
          This demo generates the FNFE. So somehow you are putting a newline into your filename. Why not check for that and fix it?
          • 2. Re: java.io.FileNotFoundException...help
            807591
            File file = new File("123_John_\nSmith.txt"); would generate a FNFE but the message is "The system cannot find the path specified"

            where as the FNFE that I am getting has the message "The filename, directory name, or volume label syntax is incorrect"
            Moreover it says "D:\objectFiles\123_John_
            Smith.txt" and there is no '\n' character listed in it..

            Hope you got what i m trying to say..
            • 3. Re: java.io.FileNotFoundException...help
              807591
              hari786 wrote:
              File file = new File("123_John_\nSmith.txt"); would generate a FNFE but the message is "The system cannot find the path specified"

              where as the FNFE that I am getting has the message "The filename, directory name, or volume label syntax is incorrect"
              Moreover it says "D:\objectFiles\123_John_
              Smith.txt" and there is no '\n' character listed in it..
              Funny, I can see the newline character just fine!

              >
              Hope you got what i m trying to say..
              The code I posted generates this runtime error for me:

              Exception in thread "main" java.io.FileNotFoundException: 123_John_
              Smith.txt (The filename, directory name, or volume label syntax is incorrect)
                   at java.io.FileOutputStream.open(Native Method)
                   at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
                   at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
                   at IOTest.main(IOTest.java:6)
              • 4. Re: java.io.FileNotFoundException...help
                807591
                hmmmm..thats weird..
                ru using jdk1.4 or 1.5?
                im using jdk1.4..it shouldnt matter anyway i guess..
                • 5. Re: java.io.FileNotFoundException...help
                  807591
                  could there be any other reason causing this exception???
                  • 6. Re: java.io.FileNotFoundException...help
                    807591
                    hari786 wrote:
                    hmmmm..thats weird..
                    ru using jdk1.4 or 1.5?
                    im using jdk1.4..it shouldnt matter anyway i guess..
                    I am using 1.6, and so should you! 1.4 is ancient and 1.5 in its Java Technology End of Life (EOL) transition period:

                    [http://java.sun.com/javase/downloads/index_jdk5.jsp]

                    I feel I have answered your question, but maybe some else could explain it better.
                    • 7. Re: java.io.FileNotFoundException...help
                      807591
                      [http://forum.java.sun.com/thread.jspa?threadID=712013&messageID=4119571] might give some ideas. may be if there is a doubt, just trim the file name just before you actually use it and then re-create the file name.

                      Edited by: prabugp on Jun 5, 2008 6:54 PM