I have created a batch file with the following commands:
@echo off
echo.>"Desktop:\testing\draft.txt"
@echo Writing text to draft.txt> Desktop:\testing\draft.txt
This means that when I execute the batch file, I want a draft.txt file with some text in it to be created in the testing folder that I have created in my desktop. I want the batch file to be executed when I run my Java class. However, I get the following error:
There is no program associated to perform the requested action. Please install a program or, if one is already installed, create an association in the Default Programs control panel.
Here is my Java class:
public class DraftBatchFile {
public DraftBatchFile() {
super();
}
/**Main Method
* @param args
*/
public static void main(String[] args) {
//Get Runtime object
Runtime runtime = Runtime.getRuntime();
try {
//Pass string in this format to open Batch file
runtime.exec("cmd /c start Desktop:\\DraftBatchFile.bat");
} catch (IOException e) {
System.out.println(e);
}
}
}
How do I get the batch file to execute the commands when I run the Java class? I am even unable to run the Java class. Why is that so? Do I have to add more code? Someone, please help me as I am new to this. Thank you so much.
Desktop:instead of the absolute path the the file? What do you mean byI am even unable to run the Java class? What is the issue?There is no program associated to perform the requested action. Please install a program or, if one is already installed, create an association in the Default Programs control panel.i got no idea why is that soDesktop:protocol since no application has been assigned as the protocol handler. But what happens when you runcmd /c start %USERPROFILE%\Desktop\DraftBatchFile.bat?cmd /c start %USERPROFILE%\Desktop\DraftBatchFile.bat, a command prompt opens and displaysThe filename, directory name, or volume label syntax is incorrect. The filename, directory name, or volume label syntax is incorrect.