The moose likes I/O and Streams and the fly likes Long File name Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Long File name" Watch "Long File name" New topic
Author

Long File name

Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
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
put your file in double quotes like \"<file name>\".
 
 
subject: Long File name
 
Threads others viewed
Drop part of a line
Long file name problem...
Saving Text file at runtime
The File Class
Problem with Copying and Renaming FIle once it reaches its limit
developer file tools