too long filename? ? ?

P

Peter

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 protected])
 
N

nos

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

Tony Morris

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


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
 
C

Chris Uppal

Peter said:
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
 
J

Jon A. Cruz

Chris said:
Peter wrote:




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?
 
C

Chris Uppal

Jon said:
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
 
N

nos

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.
 
J

Jon A. Cruz

Peter said:
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.
 
M

Mark Thornton

nos said:
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.

FileNotFoundException is what happens when you attempt to open a file
with a long path name.
 
M

Mark Thornton

Jon said:
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)
 
N

nos

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 */
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top