• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Applet not launching files with spaces in names

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

For some reason when uploadDir is set to commented value I am only able to open files where the names
do not contain spaces. For example a doc named "Test Me.doc" will not be found to load but if the file is named "TestMe.doc"
there will be no issues. Please note that this applet is not being run from a webserver; it is being executed from a shared drive on
a windows server.

Code That works......
String launchLocation = this.getCodeBase().getFile();
char drive = launchLocation.charAt(1);
String driveLetter = String.valueOf(drive);
uploadDir = driveLetter + ":/NY_GEIT_ETMS/GPS_KNOWLEDGE/upload/";

Code That will not allow spaces in file names.
//uploadDir = File.separator + File.separator + "acntnyc032" + File.separator + "dept" + File.separator + "NY_GEIT_ETMS" + File.separator + "GPS_KNOWLEDGE" + File.separator + "upload" + File.separator;


Code which launches doc
private void DocumentButtonMousePressed(java.awt.event.MouseEvent evt) {
// Open Document Code Here


String PATH = uploadDir;
String completePath = PATH + currentDocument;
File docToOpen = new File(completePath);

Desktop desktop;
if (Desktop.isDesktopSupported()) {
try {
desktop = Desktop.getDesktop();
desktop.open(docToOpen);
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}


I have played around with the below code but it also gives me an issue loading files with spaces in the name.
//File x = new File(this.getCodeBase().getPath());
//String xx = x.getPath() + File.separator + "upload" + File.separator;
//uploadDir = xx;
//System.out.print(xx);


Any help would be great. I am trying to avoid using drive names in the code at all cost.

Thanks


 
Dominic Siano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody ever come across this issue ?

Is there a better more generic way of accessing files from an applet. Like I mentioned
in my post I am trying to avoid hard coding server names and paths in my code.

I thought that this code would do the trick but when it comes time for the call
of desktop = Desktop.getDesktop(); desktop.open(docToOpen); spaces in file name
cause the file name to be found.

File x = new File(this.getCodeBase().getPath());
String xx = x.getPath() + File.separator + "upload" + File.separator;
uploadDir = xx;

Thanks....
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what's causing the problem, but if this is not an applet that's served from a webserver, but more like a desktop application, then I would make it one. Things like "getCodeBase" are really meant to be used with applets, and not in scenarios like you describe, so they may not work so well in this kind of setting.
 
Dominic Siano
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the input. I will try it with a webserver and see if I still get the same problem.
reply
    Bookmark Topic Watch Topic
  • New Topic