too long filename? ? ?

Discussion in 'Java' started by Peter, Mar 4, 2004.

  1. Peter

    Peter Guest

    Hi
    If i do the following, it will throw exception because the filename
    is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    windows XP.

    try{
    FileOutputStream f = new
    FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\2004_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004_03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\2004_03_04_jxinfo\\2004_03_04_ColumnName.html");
    }catch (Exception ee){
    ee.printStackTrace();
    }

    All the sub directory is exsit!!!

    thanks
    from Peter ()
    Peter, Mar 4, 2004
    #1
    1. Advertising

  2. Peter

    nos Guest

    I would suggest you add this
    System.out.println(ee);
    and see what the error message is.
    --------------------

    "Peter" <> wrote in message
    news:...
    > Hi
    > If i do the following, it will throw exception because the filename
    > is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    > windows XP.
    >
    > try{
    > FileOutputStream f = new
    >

    FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\200
    4_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004
    _03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\200
    4_03_04_jxinfo\\2004_03_04_ColumnName.html");
    > }catch (Exception ee){
    > ee.printStackTrace();
    > }
    >
    > All the sub directory is exsit!!!
    >
    > thanks
    > from Peter ()
    nos, Mar 4, 2004
    #2
    1. Advertising

  3. Peter

    Tony Morris Guest

    "nos" <> wrote in message
    news:vny1c.470991$na.1139603@attbi_s04...
    > I would suggest you add this
    > System.out.println(ee);
    > and see what the error message is.



    > --------------------
    > > }catch (Exception ee){
    > > ee.printStackTrace();
    > > }



    The stack trace will contain the error message.
    You need to show what that message is.

    Side note: declaring to catch java.lang.Exception is poor form.

    --
    Tony Morris
    (BInfTech, Cert 3 I.T.)
    Software Engineer
    (2003 VTR1000F)
    Sun Certified Programmer for the Java 2 Platform (1.4)
    Sun Certified Developer for the Java 2 Platform
    Tony Morris, Mar 4, 2004
    #3
  4. Peter

    Chris Uppal Guest

    Peter wrote:

    > If i do the following, it will throw exception because the filename
    > is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    > windows XP.


    There's an OS limit on the length of the filename (255 iirc). I haven't
    counted,
    but I think your filename is longer than that.

    -- chris
    Chris Uppal, Mar 4, 2004
    #4
  5. Peter

    Jon A. Cruz Guest

    Chris Uppal wrote:
    > Peter wrote:
    >
    >
    >> If i do the following, it will throw exception because the filename
    >>is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    >>windows XP.

    >
    >
    > There's an OS limit on the length of the filename (255 iirc). I haven't
    > counted,
    > but I think your filename is longer than that.


    It depends on the OS and the functions used.

    For some MS Windows API calls, prefixing the path will bypass short
    limits and allow paths of 32K.

    :)

    Fun, huh?
    Jon A. Cruz, Mar 4, 2004
    #5
  6. Peter

    Chris Uppal Guest

    Jon A. Cruz wrote:

    > For some MS Windows API calls, prefixing the path will bypass short
    > limits and allow paths of 32K.
    >
    > :)
    >
    > Fun, huh?


    Oh my, yes. Definitely another winner from Redmond.

    -- chris
    Chris Uppal, Mar 4, 2004
    #6
  7. Jon A. Cruz wrote:
    > Chris Uppal wrote:
    >
    >> Peter wrote:
    >>
    >>
    >>> If i do the following, it will throw exception because the filename
    >>> is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    >>> windows XP.

    >>
    >>
    >>
    >> There's an OS limit on the length of the filename (255 iirc). I haven't
    >> counted,
    >> but I think your filename is longer than that.

    >
    >
    > It depends on the OS and the functions used.
    >
    > For some MS Windows API calls, prefixing the path will bypass short
    > limits and allow paths of 32K.
    >
    > :)


    Note that you can't do that from within Java, as Java also parses the
    path and objects to the prefix required. There is a bug on the BugParade
    with respect to this issue.

    http://developer.java.sun.com/developer/bugParade/bugs/4403166.html

    Only 3 years old ...

    Mark Thornton
    Mark Thornton, Mar 4, 2004
    #7
  8. Peter

    Peter Guest

    Mark Thornton <> wrote in message news:<CJM1c.2862$>...
    > Jon A. Cruz wrote:
    > > Chris Uppal wrote:
    > >
    > >> Peter wrote:
    > >>
    > >>
    > >>> If i do the following, it will throw exception because the filename
    > >>> is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    > >>> windows XP.
    > >>
    > >>
    > >>
    > >> There's an OS limit on the length of the filename (255 iirc). I haven't
    > >> counted,
    > >> but I think your filename is longer than that.

    > >
    > >
    > > It depends on the OS and the functions used.
    > >
    > > For some MS Windows API calls, prefixing the path will bypass short
    > > limits and allow paths of 32K.
    > >
    > > :)

    >
    > Note that you can't do that from within Java, as Java also parses the
    > path and objects to the prefix required. There is a bug on the BugParade
    > with respect to this issue.
    >
    > http://developer.java.sun.com/developer/bugParade/bugs/4403166.html
    >
    > Only 3 years old ...
    >
    > Mark Thornton


    Big problem . Really no way to fix this? I searched the whole
    java.sun.com , but still can't find the answer.

    thanks for your reply ()
    Peter, Mar 6, 2004
    #8
  9. Peter

    nos Guest

    My book says that the constructor can only throw
    "FileNotFoundException"
    The comments in the source file for this constructor say
    ---
    * @exception FileNotFoundException if the file exists but is a directory
    * rather than a regular file, does not exist but cannot
    * be created, or cannot be opened for any other reason
    * @exception SecurityException if a security manager exists and its
    * <code>checkWrite</code> method denies write access
    * to the file.
    ---
    There is no exception for filename too long!
    So now will you tell us what the error message actually says?


    "Peter" <> wrote in message
    news:...
    > Hi
    > If i do the following, it will throw exception because the filename
    > is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    > windows XP.
    >
    > try{
    > FileOutputStream f = new
    >

    FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\200
    4_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004
    _03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\200
    4_03_04_jxinfo\\2004_03_04_ColumnName.html");
    > }catch (Exception ee){
    > ee.printStackTrace();
    > }
    >
    > All the sub directory is exsit!!!
    >
    > thanks
    > from Peter ()
    nos, Mar 6, 2004
    #9
  10. Peter

    Jon A. Cruz Guest

    Peter wrote:
    > try{
    > FileOutputStream f = new
    > FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\2004_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004_03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\2004_03_04_jxinfo\\2004_03_04_ColumnName.html");
    > }catch (Exception ee){
    > ee.printStackTrace();
    > }


    Have you tried building that up a single File object at a time?


    File dirOne = new File("projects");
    File dirTwo = new File( dirOne, "os" );
    ....
    ?


    Not sure if that would help in this case, but it would keep your Java
    code portable among other things.
    Jon A. Cruz, Mar 6, 2004
    #10
  11. nos wrote:
    > My book says that the constructor can only throw
    > "FileNotFoundException"
    > The comments in the source file for this constructor say
    > ---
    > * @exception FileNotFoundException if the file exists but is a directory
    > * rather than a regular file, does not exist but cannot
    > * be created, or cannot be opened for any other reason
    > * @exception SecurityException if a security manager exists and its
    > * <code>checkWrite</code> method denies write access
    > * to the file.
    > ---
    > There is no exception for filename too long!
    > So now will you tell us what the error message actually says?
    >


    FileNotFoundException is what happens when you attempt to open a file
    with a long path name.
    Mark Thornton, Mar 6, 2004
    #11
  12. Jon A. Cruz wrote:

    > Peter wrote:
    >
    >> try{
    >> FileOutputStream f = new
    >> FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\2004_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004_03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\2004_03_04_jxinfo\\2004_03_04_ColumnName.html");
    >>
    >> }catch (Exception ee){
    >> ee.printStackTrace();
    >> }

    >
    >
    > Have you tried building that up a single File object at a time?
    >
    >
    > File dirOne = new File("projects");
    > File dirTwo = new File( dirOne, "os" );
    > ...
    > ?
    >
    >
    > Not sure if that would help in this case, but it would keep your Java
    > code portable among other things.
    >


    It doesn't help. Windows requires a special syntax where the path
    exceeds 260 characters and Java does not support this. For such paths
    you either do all your I/O using JNI or perhaps use JNI to find the
    short versions of the names and thus possibly construct an equivalent
    path which fits within the 260 character limit. It is quite common for
    Windows programs written in other languages to fail with these paths,
    and of course Windows 9X doesn't support long paths at all. Hopefully
    when eventually this bug is fixed we will have a nice consistent
    interface that works for all path lengths (unlike the underlying Win32 API).

    Mark Thornton
    (The author of the relevant bug report)
    Mark Thornton, Mar 6, 2004
    #12
  13. Peter

    nos Guest

    Stupid me. here is from MS Visual C++
    #ifndef _MAC
    #define _MAX_PATH 260 /* max. length of full pathname */
    #define _MAX_DRIVE 3 /* max. length of drive component */
    #define _MAX_DIR 256 /* max. length of path component */
    #define _MAX_FNAME 256 /* max. length of file name component */
    #define _MAX_EXT 256 /* max. length of extension component */
    #else /* def _MAC */
    #define _MAX_PATH 256 /* max. length of full pathname */
    #define _MAX_DIR 32 /* max. length of path component */
    #define _MAX_FNAME 64 /* max. length of file name component */
    #endif /* _MAC */


    "nos" <> wrote in message
    news:ctc2c.124868$4o.164679@attbi_s52...
    > My book says that the constructor can only throw
    > "FileNotFoundException"
    > The comments in the source file for this constructor say
    > ---
    > * @exception FileNotFoundException if the file exists but is a directory
    > * rather than a regular file, does not exist but cannot
    > * be created, or cannot be opened for any other reason
    > * @exception SecurityException if a security manager exists and its
    > * <code>checkWrite</code> method denies write access
    > * to the file.
    > ---
    > There is no exception for filename too long!
    > So now will you tell us what the error message actually says?
    >
    >
    > "Peter" <> wrote in message
    > news:...
    > > Hi
    > > If i do the following, it will throw exception because the filename
    > > is too long. How to fix it? I am using JBuilder X, JDK 1.4.2 and
    > > windows XP.
    > >
    > > try{
    > > FileOutputStream f = new
    > >

    >

    FileOutputStream("projects\\os\\2004_03_04_JBuilderX\\2004_03_04_extras\\200
    >

    4_03_04_BorlandXML\\2004_03_04_doc\\2004_03_04_api-doc\\2004_03_04_com\\2004
    >

    _03_04_borland\\2004_03_04_xml\\2004_03_04_service\\2004_03_04_simpledb\\200
    > 4_03_04_jxinfo\\2004_03_04_ColumnName.html");
    > > }catch (Exception ee){
    > > ee.printStackTrace();
    > > }
    > >
    > > All the sub directory is exsit!!!
    > >
    > > thanks
    > > from Peter ()

    >
    >
    nos, Mar 7, 2004
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Waldy

    Filename Extension Too Long

    Waldy, Nov 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,555
    Randy Charles Morin
    Nov 30, 2003
  2. Replies:
    1
    Views:
    1,434
    Roland de Ruiter
    Jun 15, 2006
  3. robert
    Replies:
    1
    Views:
    4,220
    Dennis Lee Bieber
    Jul 1, 2006
  4. Moqtar

    Filename too long error

    Moqtar, Dec 5, 2006, in forum: Python
    Replies:
    0
    Views:
    306
    Moqtar
    Dec 5, 2006
  5. Replies:
    0
    Views:
    570
Loading...

Share This Page