所谓照猫画虎,想要知道生成桌面快捷方式,最快的方法就是去看微软的开发文档,微软官方文档链接,虽然本人英语水平有限,但是借助谷歌翻译基本阅读还是可以保证的
前言基本没什么好看的,直接看目录
第一章是一些名词解释还有一些说明,没啥用,第二章才是我们需要的
大意就是说第一段字节标记了时间和可选结构还有其他一些信息,第二段指定链接的目标,也就是我们快捷方式指定的文件,那么如果只是为了实现最简单的快捷方式,我们只需要这两段字节即可
依次往下查询,最终确定所需的字节
import javax.swing.filechooser.FileSystemView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
/**
* 贺驰宇
* 2020-3-12
*/
public class CreateShortcut {
private String prefixFile;
private HashMap<String,String> pathAndName;
/**
* 开机启动目录
*/
public final static String startup=System.getProperty("user.home")+
"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\";
/**
* 桌面目录
*/
public final static String desktop= FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath()+"\\";
/**
* 文件头,固定字段
*/
private byte[] headFile={
0x4c,0x00,0x00,0x00,
0x01, 0x14,0x02,0x00,0x00,0x00,0x00,0x00,
(byte) 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46
};
/**
* 文件头属性
*/
private byte[] fileAttributes={
(byte) 0x93,0x00,0x08,0x00,//可选文件属性
0x20, 0x00, 0x00, 0x00,//目标文件属性
0x00,0x00,0x00,0x00,0x00