This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Long file name problem  RSS feed

 
Pratik Khetia
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
In my application, I am opening a file from its location but it doesnt work if the file is in My Document or Program Files like that...so How do I take care of the long file names even it doesn't support the file name with spaces..
Any help would be appriciated !!
thanks
Pratik
 
Rowan Brownlee
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pratik,
The following works ok as a reader. Is this different to what you're doing?
cheerio
rowan


 
Pratik Khetia
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rowan Brownlee:
[B]Hi Pratik,
The following works ok as a reader. Is this different to what you're doing?
cheerio
rowan

[/B]


Hi Here is my code...which opens a file from the local machine..
import java.lang.Integer;
import java.io.*;
public class OpenFile1 {
public OpenFile1(String fileName)
{
String FileName="";
FileName=fileName;
String Path="";
FileName=FileName.toUpperCase();
String osName = System.getProperty("os.name" );
Path="Start " + fileName;
if( osName.equalsIgnoreCase( "Windows NT" ) | | osName.equalsIgnoreCase("Windows 2000" )| | osName.equalsIgnoreCase( "Windows XP" ))
{
Path="cmd.exe Start /c" + fileName;
}
Runtime rt = Runtime.getRuntime();
try{
try
{
System.out.println("Path " + Path);
rt.exec(Path);
}
catch(IOException io)
{
System.out.println("Exception thrown: " + io);
}
}
catch (IllegalArgumentException e){System.out.println("Exception thrown: " + e);
}
}
public static void main(String args[])
{
// please enter the filename here !!
//new OpenFile1("c:\\mydocu~1\\phone.xls");
new OpenFile1("c:\\My Documents\\phone.xls");
}
}
 
Pratik Khetia
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the problem is still there !
Like is you give
C:\My Documents\ File name (it will give error)
but if u give
C:\mydocu~1\filename then only it works
Can you help me find a way to solve that problem ??

thanks
Pratik
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect the problem is not long file names, but rather, file names with spaces in them. You probably need to surround the filename with quotes in order for the system to recognize it as a single file name. Try replacing

with


 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, be aware that in Java programs, we do not capitalize the names of variables (except CONSTANTS_IN_CAPS_WITH_UNDERSCORES) and so your "Path" variable looks like a class name. I strongly suggest following standard Java conventions so you don't needlessly confuse the people who are trying to help you. "Path" should be "path", "FileName" should be "fileName", etc.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!