0
我想inwindows的代碼,我在這裏使用的庫創建快捷方式: http://alumnus.caltech.edu/~jimmc/jshortcut/jshortcut/README.html 也相應代碼:在Java中創建快捷方式以lib JShortcut
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 ...非常感謝
是完整的代碼?我沒有看到從shell運行java程序所需的'public void main(String args []){}''。 –
您是否將JShellLink添加到類路徑中? – Deltharis
@Deltharis ....不,如果文件系統是這樣的:H:\ src \ TRUST在這個文件夾中有jshortcut.jar,remove.class,remove.java。類路徑應該是什麼? JSHEllLink.class中的代碼表示將路徑設置爲.dll文件,但.dll文件位於jar中.... thx很多 – printemp