代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
让文件对话框真正支持Windows快捷方式
作者:
DDT
/ 发布于
2012/6/25
/
703
让文件对话框真正支持Windows快捷方式
<div>public class LnkParser { public LnkParser(File f) throws Exception { parse(f); } public 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();</div> <div>// get the flags byte byte flags = link[0x14];</div> <div>// get the file attributes byte final int file_atts_offset = 0x18; byte fileatts = link[file_atts_offset]; byte is_dir_mask = (byte)0x10; if((fileatts & is_dir_mask) > 0) { is_dir = true; } else { is_dir = false; } <div>// if the shell settings are present, skip them final int shell_offset = 0x4c; int shell_len = 0; if((flags & 0x1) > 0) { // the plus 2 accounts for the length marker itself shell_len = bytes2short(link,shell_offset) + 2; } // get to the file block int file_start = 0x4c + shell_len;</div> <div>// get the local volume and local system values int local_sys_off = link[file_start+0x10] + file_start; real_file = getNullDelimitedString(link,local_sys_off); p("real filename = " + real_file); } 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. static int bytes2short(byte[] bytes, int off) { return bytes[off] | (bytes[off+1]<<8); } private boolean is_dir; public boolean isDirectory() { return is_dir; } private String real_file; public String getRealFilename() { return real_file; } } public class ShortcutFileSystemView extends FileSystemView {</div> <div>public Boolean isTraversable(File f) { if(isDirLink(f)) { return new Boolean(true); } return super.isTraversable(f); } public File[] getFiles(File dir, boolean useFileHiding) { if(isDirLink(dir)) { dir = getRealFile(dir); } return super.getFiles(dir,useFileHiding); } private boolean isDirLink(File f) { try { if(f.getName().toLowerCase().endsWith(".lnk")) { if(new LnkParser(f).isDirectory()) { return true; } } } catch (Exception ex) { System.out.println("ex: " + ex); ex.printStackTrace(); } return false; } <div>private File getRealFile(File file) { try { return new File(new LnkParser(file).getRealFilename()); } catch (Exception ex) { System.out.println("ex: " + ex); ex.printStackTrace(); return null; } } public boolean isDirLink(File f) { try { if(f.getName().toLowerCase().endsWith(".lnk")) { LnkParser parser = new LnkParser(f); if(parser.isDirectory()) { return true; } } <div>} catch (Exception ex) { System.out.println("exception: " + ex.getMessage()); ex.printStackTrace(); } return false; } } public class ShortcutTest { public static void main(String[] args) throws Exception { FileSystemView fsv = new ShortcutFileSystemView(); JFileChooser chooser = new JFileChooser(); chooser.setFileSystemView(fsv); chooser.setFileView(new ShortcutFileView()); chooser.showOpenDialog(null); } } </div>
试试其它关键字
文件对话框
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
实现测量程序运行时间及cpu使用时间
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
DDT
贡献的其它代码
(
160
)
.
Oracle统计表的数据行和数据块信息
.
html标签闭合检测与修复
.
Powershell日期计算
.
Powershell的Base64编解码
.
Powershell并行循环
.
Powershell目录中搜索文本
.
Powershell枚举远程机器上的本地权限组
.
VBScript解析csv文件
.
快速排序之Powershell
.
批处理输出格式化时间字符串
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3