This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Long File name

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
put your file in double quotes like \"<file name>\".
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic