我想用代码在windows中创建快捷方式,我在这里使用库:http://alumnus.caltech.edu/~jimmc/jshortcut/jshortcut/README.html 还有 相应的代码:
import net.jimmc.jshortcut.JShellLink;
public class remove {
public static void main(String[] args) throws Exception{
String path = new String ("/home/test.csv");
readAndDelete(path, true, StandardCharsets.UTF_8);
}
private static void readAndDelete(String path, boolean ignoreHeader,Charset encoding) throws IOException {
File file = new File(path);
CSVParser parser = CSVParser.parse(file, encoding,CSVFormat.DEFAULT.withHeader());
List<CSVRecord> records = parser.getRecords();
List<String> docRecord = new ArrayList<String>();
List<String> shortpath = new ArrayList<String>();
for (CSVRecord doctype : records){
docRecord.add(doctype.get(0).toString());
shortpath.add(doctype.get(1).toString());
}
int recordlength = docRecord.size();
for(String eachdocRecord:docRecord){
try {
Path pathtemp=Paths.get(eachdocRecord);
Files.delete(pathtemp);
} catch (NoSuchFileException x) {
System.err.format("%s: no such" + " file or directory%n", path);
} catch (DirectoryNotEmptyException x) {
System.err.format("%s not empty%n", path);
} catch (IOException x) {
// File permission problems are caught here.
System.err.println(x);
}
}
for(int i=0; i<recordlength; i++){
JShellLink link = new JShellLink();
String pointpath=shortpath.get(i);
String originalpath = docRecord.get(i);
String[] parts = pointpath.split("\\\\");
int partssize= parts.length;
String name=parts[partssize-1];
String[] originalparts = originalpath.split("\\\\");
int originalsize = originalparts.length;
int lastlength = originalparts[originalsize-1].length();
String foldername = originalpath.substring(0,originalpath.length()-lastlength);
link.setFolder(foldername);
link.setName(name);
link.setPath(pointpath);
link.save();
}
}
}
我在 Windows 命令提示符下运行它,但总是异常:
Exception in thread "main" java.lang.NoClassDefFoundError:net/jimmc/jshortcut/JShellLink
我成功编译了.class ...任何人都可以保存nme ...非常感谢