java 如何打开程序旁边的快捷方式?
java how do you open a shortcut next to the program?
嗨,我正在尝试 run/open 从我的 jar 旁边的文件夹中创建快捷方式 file.I 似乎无法正常工作,因为它一直在说
The system cannot find the file specified
你能指出我做错了什么吗?
JButton btnInstall = new JButton("Install/Run");
btnInstall.setEnabled(false);
btnInstall.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ChangePath(ProgramAdder.programs.get(count).ProgramPath.toString());
System.out.print(ProgramAdder.programs.get(count).ProgramPath.toString());
}
});
btnInstall.setBounds(173, 226, 116, 45);
frame.getContentPane().add(btnInstall);
public void ChangePath(String Path){
try {
Process process= Runtime.getRuntime().exec(Path);
} catch (IOException e) {
e.printStackTrace();
}
}
.
package Logic;
import java.util.ArrayList;
import java.util.List;
public class ProgramAdder {
public static List<Programs> programs = new ArrayList<Programs>( );
public static void ProgramList(){
ProgramAdder.addProgram("HD Sentinel","/Shortcuts In Order/1 - HDSentinel.lnk");
ProgramAdder.addProgram("Defraggler","/Shortcuts In Order/2 - Defraggler.lnk");
ProgramAdder.addProgram("CC Cleaner","/Shortcuts In Order/3 - CCCLEANER.lnk");
ProgramAdder.addProgram("Hit Man Pro 64Bit","/Shortcuts In Order/4 - HitManPro 32bit.lnk");
ProgramAdder.addProgram("Hit Man Pro 32Bit","/Shortcuts In Order/4 - HitManPro 64bit.lnk");
ProgramAdder.addProgram("Super Anti Spyware","/Shortcuts In Order/5 - SuperAntiSpyware.lnk");
ProgramAdder.addProgram("Malware Bytes","/Shortcuts In Order/6 - MalwareBytes.lnk");
}
public static void addProgram(String ProgramName,String ProgramPath){
Programs p = new Programs();
p.ProgramName = ProgramName;
p.ProgramPath = ProgramPath;
programs.add(p);
}
}
我在 main 中尝试了 运行 这个函数,但我仍然遇到同样的错误
package Logic;
import java.io.IOException;
public class OpenTets {
public static void OpenProgram(){
try {
Process process= Runtime.getRuntime().exec("/Shortcuts In Order/1 - HDSentinel.lnk");
} catch (IOException e) {
e.printStackTrace();
}
}
}
如果您不需要保留 Runtime.exec
返回的 Process
对象,那么您可以使用更简单的 Desktop.getDesktop().open
。提供您要打开的 File
。
嗨,我正在尝试 run/open 从我的 jar 旁边的文件夹中创建快捷方式 file.I 似乎无法正常工作,因为它一直在说
The system cannot find the file specified
你能指出我做错了什么吗?
JButton btnInstall = new JButton("Install/Run");
btnInstall.setEnabled(false);
btnInstall.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ChangePath(ProgramAdder.programs.get(count).ProgramPath.toString());
System.out.print(ProgramAdder.programs.get(count).ProgramPath.toString());
}
});
btnInstall.setBounds(173, 226, 116, 45);
frame.getContentPane().add(btnInstall);
public void ChangePath(String Path){
try {
Process process= Runtime.getRuntime().exec(Path);
} catch (IOException e) {
e.printStackTrace();
}
}
.
package Logic;
import java.util.ArrayList;
import java.util.List;
public class ProgramAdder {
public static List<Programs> programs = new ArrayList<Programs>( );
public static void ProgramList(){
ProgramAdder.addProgram("HD Sentinel","/Shortcuts In Order/1 - HDSentinel.lnk");
ProgramAdder.addProgram("Defraggler","/Shortcuts In Order/2 - Defraggler.lnk");
ProgramAdder.addProgram("CC Cleaner","/Shortcuts In Order/3 - CCCLEANER.lnk");
ProgramAdder.addProgram("Hit Man Pro 64Bit","/Shortcuts In Order/4 - HitManPro 32bit.lnk");
ProgramAdder.addProgram("Hit Man Pro 32Bit","/Shortcuts In Order/4 - HitManPro 64bit.lnk");
ProgramAdder.addProgram("Super Anti Spyware","/Shortcuts In Order/5 - SuperAntiSpyware.lnk");
ProgramAdder.addProgram("Malware Bytes","/Shortcuts In Order/6 - MalwareBytes.lnk");
}
public static void addProgram(String ProgramName,String ProgramPath){
Programs p = new Programs();
p.ProgramName = ProgramName;
p.ProgramPath = ProgramPath;
programs.add(p);
}
}
我在 main 中尝试了 运行 这个函数,但我仍然遇到同样的错误
package Logic;
import java.io.IOException;
public class OpenTets {
public static void OpenProgram(){
try {
Process process= Runtime.getRuntime().exec("/Shortcuts In Order/1 - HDSentinel.lnk");
} catch (IOException e) {
e.printStackTrace();
}
}
}
如果您不需要保留 Runtime.exec
返回的 Process
对象,那么您可以使用更简单的 Desktop.getDesktop().open
。提供您要打开的 File
。