too long filename? ? ?  
Author Message
cmk128





PostPosted: 2004-3-4 12:20:00 Top

java-programmer, too long filename? ? ? 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 (email***@***.com)
 
nos





PostPosted: 2004-3-4 12:37:00 Top

java-programmer >> too long filename? ? ? I would suggest you add this
System.out.println(ee);
and see what the error message is.
--------------------

"Peter" <email***@***.com> wrote in message
news:email***@***.com...
> 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 (email***@***.com)


 
Tony Morris





PostPosted: 2004-3-4 13:07:00 Top

java-programmer >> too long filename? ? ?

"nos" <email***@***.com> 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


 
 
Chris Uppal





PostPosted: 2004-3-4 15:45:00 Top

java-programmer >> too long filename? ? ? 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



 
 
Jon A. Cruz





PostPosted: 2004-3-4 16:45:00 Top

java-programmer >> too long filename? ? ? 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?

 
 
Chris Uppal





PostPosted: 2004-3-4 18:48:00 Top

java-programmer >> too long filename? ? ? 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


 
 
Mark Thornton





PostPosted: 2004-3-5 4:56:00 Top

java-programmer >> too long filename? ? ? 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

 
 
cmk128





PostPosted: 2004-3-6 9:54:00 Top

java-programmer >> too long filename? ? ? Mark Thornton <email***@***.com> wrote in message news:<CJM1c.2862$email***@***.com>...
> 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 (email***@***.com)
 
 
nos





PostPosted: 2004-3-6 12:30:00 Top

java-programmer >> too long filename? ? ? 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" <email***@***.com> wrote in message
news:email***@***.com...
> 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 (email***@***.com)


 
 
Jon A. Cruz





PostPosted: 2004-3-6 13:15:00 Top

java-programmer >> too long filename? ? ? 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.

 
 
Mark Thornton





PostPosted: 2004-3-6 17:50:00 Top

java-programmer >> too long filename? ? ? 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





PostPosted: 2004-3-6 17:58:00 Top

java-programmer >> too long filename? ? ? 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)

 
 
nos





PostPosted: 2004-3-7 13:30:00 Top

java-programmer >> too long filename? ? ? 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" <email***@***.com> 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" <email***@***.com> wrote in message
> news:email***@***.com...
> > 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 (email***@***.com)
>
>