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  RSS feed

 
Pratik Khetia
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to open a file from my application by passing the filename as a string parameter here is the code for that..

import java.lang.Integer;
import java.io.*;
public class OpenFile {
public OpenFile(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
{
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 OpenFile("c:\\temp\\file.txt");
}
}
It doesn't work for the long file/folder names like...
c:\My Document\file.txt will not work.....
How do I solve this problem ??
Any help would be very appriciated !
thanks
Pratik
 
jigar shah
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put your file in double quotes like \"<file name>\".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!