当前位置:我的异常网» 行业应用 » java取得快捷方式指向的路径

java取得快捷方式指向的路径

www.myexceptions.net  网友分享于:2013-08-17  浏览:5次

java获得快捷方式指向的路径

import java.io.ByteArrayOutputStream;

import java.io.File;

import java.io.FileInputStream;

/**

* 获得快捷方式指向的路径

* @author shk

*

*/

public class LnkParser {

public static void main(String[] args) throws Exception {

new LnkParser(new File("C://temps//config.text.lnk"));

}

public LnkParser(File f) throws Exception {

parse(f);

}

private boolean is_dir;

public boolean isDirectory() {

return is_dir;

}

private String real_file;

public String getRealFilename() {

return real_file;

}

private void parse(File f) throws Exception {

// read the entire file into a byte buffer

FileInputStream fin = new FileInputStream(f);

ByteArrayOutputStream bout = new ByteArrayOutputStream();

byte[] buff = new byte[256];

while (true) {

int n = fin.read(buff);

if (n == -1) {

break;

}

bout.write(buff, 0, n);

}

fin.close();

byte[] link = bout.toByteArray();

// get the flags byte

byte flags = link[0x14];

// get the file attributes byte

final int file_atts_offset = 0x18;

byte file_atts = link[file_atts_offset];

byte is_dir_mask = (byte) 0x10;

if ((file_atts & is_dir_mask) > 0) {

is_dir = true;

} else {

is_dir = false;

}

// if the shell settings are present, skip them

final int shell_offset = 0x4c;

final byte has_shell_mask = (byte) 0x01;

int shell_len = 0;

if ((flags & has_shell_mask) > 0) {

// the plus 2 accounts for the length marker itself

shell_len = bytes2short(link, shell_offset) + 2;

}

// get to the file settings

int file_start = 0x4c + shell_len;

// get the local volume and local system values

final int basename_offset_offset = 0x10;

final int finalname_offset_offset = 0x18;

int basename_offset = link[file_start + basename_offset_offset]

+ file_start;

int finalname_offset = link[file_start + finalname_offset_offset]

+ file_start;

String basename = getNullDelimitedString(link, basename_offset);

String finalname = getNullDelimitedString(link, finalname_offset);

real_file = basename + finalname;

System.out.println("快捷方式指向的文件路径为:"+real_file);

}

private static String getNullDelimitedString(byte[] bytes, int off) {

int len = 0;

// count bytes until the null character (0)

while (true) {

if (bytes[off + len] == 0) {

break;

}

len++;

}

return new String(bytes, off, len);

}

/*

* convert two bytes into a short note, this is little endian because it's

* for an Intel only OS.

*/

private static int bytes2short(byte[] bytes, int off) {

int n = 0;

for (int i = start, k = start + len % 5; i < k; i++) {

n += (bys[i] & 0xff) << (i * (8));

}

return n;

}

文章评论

java快捷键查看目录,java取得快捷方式指向的路径相关推荐

  1. java 包和目录,Java中包和目录的区别

    In a Java Project, does keeping all the .java files in the same folder mean they are in the same pac ...

  2. java 重命名目录_java – 重命名目录时重命名文件

    尝试重命名目录名称和文件名. try { File dir = new File("DIR"); dir.mkdir(); File file1 = new File(dir,&q ...

  3. Java 答疑:为什么修改 Java 环境变量之后 java -version 不变?解决方式汇总

    文章目录 前言 一.错误场景预演 1.1.查看本地旧版本 1.2.java -version 不变问题产生 二.检查新安装 JDK 是否配置正确 2.1.下载并解压目标 JDK 2.2.配置 Java ...

  4. JAVA习题大全之java期末考试复习预测题一

    JAVA习题大全 目录 JAVA习题大全 java期末考试复习预测题A java期末考试复习预测题B java期末考试复习预测题C java期末考试复习预测题D java期末考试复习预测题E java ...

  5. 初学Java(一)Java介绍

    Java介绍 文章目录 Java介绍 前言 一.Java是什么及它的用途 二.Java加载与执行 1. Java加载与执行过程 2. JDK.JRE.JVM各自是什么以及之间的关系 3. 编写.编译. ...

  6. JAVA classpath设置方式启动详解:java class名、java -jar

    java classpath设置方式启动详解:java className.java -jar 文章目录 java classpath设置方式启动详解:java className.java -jar ...

  7. java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at java.lang.It

    错误信息: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String at java.lan ...

  8. sqlite命令行查看数据显示列头、java访问sqlite、java命令指定classpath

    sqlite3附加数据库:attach database; 看一下表的数据: 查看表架构:.schema tablename:以前这命令都没问题,能显示表结构,但这次显示不出,也没提示出错: 使用 s ...

  9. Java如何查看死锁?

    转载自 https://blog.csdn.net/u014039577/article/details/52351626 Java中当我们的开发涉及到多线程的时候,这个时候就很容易遇到死锁问题,刚开 ...

最新文章

  1. Log4j源代码学习
  2. jSearch(聚搜) v0.5.0 发布,多项更新和体验优化
  3. 经典面试题:在这个场景下,你怎么进行性能调优?
  4. 同余方程———扩展欧几里得
  5. python字典视图
  6. thinkphp如何通过php请求接口,thinkphp怎么做json数据接口
  7. 计算机组成原理第二章数据,计算机组成原理第二章数据在计算机中的表示
  8. 搬寝室(HDU 1421 DP)
  9. UI设计APP素材可编辑模板|底部标签式导航
  10. 如何利用FineBI做财务分析
  11. 地脚螺钉直径系列_机械系统通用件——螺栓、螺钉和螺柱国家标准
  12. Postman安装使用
  13. 隐私计算头条周刊(10.9-10.15)
  14. 个人ID的搜索引擎结果分析与联想
  15. 基于决策树算法对良/恶性乳腺癌肿瘤预测
  16. Mac苹果移动硬盘数据丢失怎么恢复?
  17. 思科路由器存储分类介绍
  18. 牛客网赛码网 输入输出格式
  19. java运算符优先级
  20. 数仓 即席查询 之 Persto

热门文章

  1. nlp3-有限自动机FLandFA
  2. 国科大prml15-BP
  3. SpringBoot整合Redis集群版本问题
  4. 斯坦福大学CS520知识图谱系列课程学习笔记:第二讲如何构建知识图谱
  5. Django - 模板相关
  6. Linux C语言 文件操作
  7. Mac idea中git igenore设置
  8. BZOJ-4300 绝世好(蛋疼)题 DP(递推)
  9. 【Tech】Mac上安装MAMP打开本地网页
  10. Source Server + Symbol Server