Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet not launching files with spaces in names

 
Dominic Siano
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....
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic