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
Joined: Feb 19, 2002
Posts: 1
posted
0
put your file in double quotes like \"<file name>\".