Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. private File createrunbat(String str,String par)
  2. {
  3. if(str.startsWith("Text Editor-",0))
  4. {
  5. str=str.replaceFirst("Text Editor-","");
  6. }
  7. String sng,s2;
  8. File fe;
  9. try{
  10.  
  11. FileOutputStream fos;
  12. DataOutputStream dos;
  13.  
  14. sng=str;
  15.  
  16. int a=sng.indexOf(".");
  17.  
  18. sng=sng.substring(0,a);
  19.  
  20. file=new File(jfc.getSelectedFile().getParent(),sng+".bat");
  21.  
  22. fd=file.getAbsoluteFile();
  23.  
  24. str=fd.getParent().substring(0, 2);
  25.  
  26. fos=new FileOutputStream(file);
  27. dos=new DataOutputStream(fos);
  28.  
  29. dos.writeBytes("@echo off n");
  30. dos.writeBytes("cd\"+"n");
  31.  
  32. if(fd.getParentFile().isDirectory())
  33. {
  34. dos.writeBytes(str+"n");
  35. }
  36. s2=jfc.getSelectedFile().getParent();//I am having single quote problem from here
  37. dos.writeBytes("cd "+s2+"\"+"n");
  38. dos.writeBytes("javac "+sng+".java"+"n");
  39. dos.writeBytes("java "+sng+" "+par+"n");
  40. dos.writeBytes("pause n");
  41. dos.writeBytes("exit n");
  42. dos.close();
  43. }
  44. catch(FileNotFoundException ex)
  45. {
  46. }
  47. catch(IOException ex2)
  48. {
  49. JOptionPane.showMessageDialog(this,ex2.toString());
  50. }
  51.  
  52. return fd;
  53. }
  54.  
  55. Windows cannot find 'C:Program'.
  56.  
  57. 'C:Program FilesSomePlace...'
  58. ^ gets cut on whitespace and becomes two arguments instead of one:
  59. 'C:Program' and 'FilesSomePlace...'
  60.  
  61. '"C:Program FilesSomePlace..."'
  62. ^ quotes will keep the path together as a single argument
  63.  
  64. String safePath = String.format(""%s"", jfc.getSelectedFile().getParent().getAbsolutePath());
  65.  
  66. dos.writeBytes ("cd "" + s2 +"""+"n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement