免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2662 | 回复: 3
打印 上一主题 下一主题

代码的宽度可以设置成 100% 吗?现在的代码显示宽度太窄了…… [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-07-23 17:37 |只看该作者 |倒序浏览
如下所示
  1. import java.io.*;
  2. import java.nio.*;
  3. import java.util.Date;

  4. // Java Native Access: http://jna.dev.java.net
  5. // Test with jna-3.2.7
  6. import com.sun.jna.*;
  7. import com.sun.jna.ptr.*;
  8. import com.sun.jna.win32.*;
  9. import com.sun.jna.platform.win32.*;


  10. public class WindowsFileTime
  11. {
  12.         public static final int GENERIC_READ = 0x80000000;
  13.         //public static final int GENERIC_WRITE = 0x40000000;        // defined in com.sun.jna.platform.win32.WinNT
  14.         public static final int GENERIC_EXECUTE = 0x20000000;
  15.         public static final int GENERIC_ALL = 0x10000000;

  16.         // defined in com.sun.jna.platform.win32.WinNT
  17.         //public static final int CREATE_NEW = 1;
  18.         //public static final int CREATE_ALWAYS = 2;
  19.         //public static final int OPEN_EXISTING = 3;
  20.         //public static final int OPEN_ALWAYS = 4;
  21.         //public static final int TRUNCATE_EXISTING = 5;

  22.         public interface MoreKernel32 extends Kernel32
  23.         {
  24.                 static final MoreKernel32 instance = (MoreKernel32)Native.loadLibrary ("kernel32", MoreKernel32.class, W32APIOptions.DEFAULT_OPTIONS);
  25.                 boolean GetFileTime (WinNT.HANDLE hFile, WinBase.FILETIME lpCreationTime, WinBase.FILETIME lpLastAccessTime, WinBase.FILETIME lpLastWriteTime);
  26.                 boolean SetFileTime (WinNT.HANDLE hFile, final WinBase.FILETIME lpCreationTime, final WinBase.FILETIME lpLastAccessTime, final WinBase.FILETIME lpLastWriteTime);
  27.         }

  28.         static MoreKernel32 win32 = MoreKernel32.instance;
  29.         //static Kernel32 _win32 = (Kernel32)win32;

  30.         static WinBase.FILETIME _creationTime = new WinBase.FILETIME ();
  31.         static WinBase.FILETIME _lastWriteTime = new WinBase.FILETIME ();
  32.         static WinBase.FILETIME _lastAccessTime = new WinBase.FILETIME ();

  33.         static boolean GetFileTime (String sFileName, Date creationTime, Date lastWriteTime, Date lastAccessTime)
  34.         {
  35.                 WinNT.HANDLE hFile = OpenFile (sFileName, GENERIC_READ);        // may be WinNT.GENERIC_READ in future jna version.
  36.                 if (hFile == WinBase.INVALID_HANDLE_VALUE) return false;

  37.                 boolean rc = win32.GetFileTime (hFile, _creationTime, _lastAccessTime, _lastWriteTime);
  38.                 if (rc)
  39.                 {
  40.                         if (creationTime != null) creationTime.setTime (_creationTime.toLong());
  41.                         if (lastAccessTime != null) lastAccessTime.setTime (_lastAccessTime.toLong());
  42.                         if (lastWriteTime != null) lastWriteTime.setTime (_lastWriteTime.toLong());
  43.                 }
  44.                 else
  45.                 {
  46.                         int iLastError = win32.GetLastError();
  47.                         System.out.print ("获取文件时间失败,错误码:" + iLastError + " " + GetWindowsSystemErrorMessage (iLastError));
  48.                 }
  49.                 win32.CloseHandle (hFile);
  50.                 return rc;
  51.         }
  52.         static boolean SetFileTime (String sFileName, final Date creationTime, final Date lastWriteTime, final Date lastAccessTime)
  53.         {
  54.                 WinNT.HANDLE hFile = OpenFile (sFileName, WinNT.GENERIC_WRITE);
  55.                 if (hFile == WinBase.INVALID_HANDLE_VALUE) return false;

  56.                 ConvertDateToFILETIME (creationTime, _creationTime);
  57.                 ConvertDateToFILETIME (lastWriteTime, _lastWriteTime);
  58.                 ConvertDateToFILETIME (lastAccessTime, _lastAccessTime);

  59.                 //System.out.println ("creationTime: " + creationTime);
  60.                 //System.out.println ("lastWriteTime: " + lastWriteTime);
  61.                 //System.out.println ("lastAccessTime: " + lastAccessTime);

  62.                 //System.out.println ("_creationTime: " + _creationTime);
  63.                 //System.out.println ("_lastWriteTime: " + _lastWriteTime);
  64.                 //System.out.println ("_lastAccessTime: " + _lastAccessTime);

  65.                 boolean rc = win32.SetFileTime (hFile, creationTime==null?null:_creationTime, lastAccessTime==null?null:_lastAccessTime, lastWriteTime==null?null:_lastWriteTime);
  66.                 if (! rc)
  67.                 {
  68.                         int iLastError = win32.GetLastError();
  69.                         System.out.print ("设置文件时间失败,错误码:" + iLastError + " " + GetWindowsSystemErrorMessage (iLastError));
  70.                 }
  71.                 win32.CloseHandle (hFile);
  72.                 return rc;
  73.         }
  74.         static void ConvertDateToFILETIME (Date date, WinBase.FILETIME ft)
  75.         {
  76.                 if (ft != null)
  77.                 {
  78.                         long iFileTime = 0;
  79.                         if (date != null)
  80.                         {
  81.                                 iFileTime = WinBase.FILETIME.dateToFileTime (date);
  82.                                 ft.dwHighDateTime = (int)((iFileTime >> 32) & 0xFFFFFFFFL);
  83.                                 ft.dwLowDateTime = (int)(iFileTime & 0xFFFFFFFFL);
  84.                         }
  85.                         else
  86.                         {
  87.                                 ft.dwHighDateTime = 0;
  88.                                 ft.dwLowDateTime = 0;
  89.                         }
  90.                 }
  91.         }

  92.         static WinNT.HANDLE OpenFile (String sFileName, int dwDesiredAccess)
  93.         {
  94.                 WinNT.HANDLE hFile = win32.CreateFile (
  95.                         sFileName,
  96.                         dwDesiredAccess,
  97.                         0,
  98.                         null,
  99.                         WinNT.OPEN_EXISTING,
  100.                         0,
  101.                         null
  102.                         );
  103.                 if (hFile == WinBase.INVALID_HANDLE_VALUE)
  104.                 {
  105.                         int iLastError = win32.GetLastError();
  106.                         System.out.print ("        打开文件失败,错误码:" + iLastError + " " + GetWindowsSystemErrorMessage (iLastError));
  107.                 }
  108.                 return hFile;
  109.         }
  110.         static String GetWindowsSystemErrorMessage (int iError)
  111.         {
  112.                 char[] buf = new char[255];
  113.                 CharBuffer bb = CharBuffer.wrap (buf);
  114.                 //bb.clear ();
  115.                 //PointerByReference pMsgBuf = new PointerByReference ();
  116.                 int iChar = win32.FormatMessage (
  117.                                 WinBase.FORMAT_MESSAGE_FROM_SYSTEM
  118.                                         //| WinBase.FORMAT_MESSAGE_IGNORE_INSERTS
  119.                                         //|WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER
  120.                                         ,
  121.                                 null,
  122.                                 iError,
  123.                                 0x0804,
  124.                                 bb, buf.length,
  125.                                 //pMsgBuf, 0,
  126.                                 null
  127.                         );
  128.                 //for (int i=0; i<iChar; i++)
  129.                 //{
  130.                 //        System.out.print (" ");
  131.                 //        System.out.print (String.format("%02X", buf[i]&0xFFFF));
  132.                 //}
  133.                 bb.limit (iChar);
  134.                 //System.out.print (bb);
  135.                 //System.out.print (pMsgBuf.getValue().getString(0));
  136.                 //win32.LocalFree (pMsgBuf.getValue());
  137.                 return bb.toString ();
  138.         }

  139.         public static void main (String[] args) throws Exception
  140.         {
  141.                 if (args.length == 0)
  142.                 {
  143.                         System.out.println ("获取 Windows 的文件时间(创建时间、最后修改时间、最后访问时间)");
  144.                         System.out.println ("用法:");
  145.                         System.out.println ("        java -cp .;..;jna.jar;platform.jar WindowsFileTime [文件名1] [文件名2]...");
  146.                         return;
  147.                 }

  148.                 boolean rc;
  149.                 java.sql.Timestamp ct = new java.sql.Timestamp(0);
  150.                 java.sql.Timestamp wt = new java.sql.Timestamp(0);
  151.                 java.sql.Timestamp at = new java.sql.Timestamp(0);

  152.                 for (String sFileName : args)
  153.                 {
  154.                         System.out.println ("文件 " + sFileName);

  155.                         rc = GetFileTime (sFileName, ct, wt, at);
  156.                         if (rc)
  157.                         {
  158.                                 System.out.println ("        创建时间:" + ct);
  159.                                 System.out.println ("        修改时间:" + wt);
  160.                                 System.out.println ("        访问时间:" + at);
  161.                         }
  162.                         else
  163.                         {
  164.                                 //System.out.println ("GetFileTime 失败");
  165.                         }


  166.                         //wt.setTime (System.currentTimeMillis());
  167.                         wt = java.sql.Timestamp.valueOf("2010-07-23 00:00:00");
  168.                         rc = SetFileTime (sFileName, null, wt, null);
  169.                         if (rc)
  170.                         {
  171.                                 System.out.println ("SetFileTime (最后修改时间) 成功");
  172.                         }
  173.                         else
  174.                         {
  175.                                 //System.out.println ("SetFileTime 失败");
  176.                         }
  177.                 }
  178.         }
  179. }
复制代码

论坛徽章:
49
15-16赛季CBA联赛之福建
日期:2016-06-22 16:22:002015年亚洲杯之中国
日期:2015-01-23 16:25:12丑牛
日期:2015-01-20 09:39:23未羊
日期:2015-01-14 23:55:57巳蛇
日期:2015-01-06 18:21:36双鱼座
日期:2015-01-02 22:04:33午马
日期:2014-11-25 09:58:35辰龙
日期:2014-11-18 10:40:07寅虎
日期:2014-11-13 22:47:15申猴
日期:2014-10-22 15:29:50摩羯座
日期:2014-08-27 10:49:43辰龙
日期:2014-08-21 10:47:58
2 [报告]
发表于 2010-07-23 18:48 |只看该作者
收到,这个可以改的,呵呵,尽快给大家答复,呵呵

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
3 [报告]
发表于 2010-07-25 15:58 |只看该作者
非常赞同设置成100%

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
4 [报告]
发表于 2010-07-28 11:38 |只看该作者
回复 2# send_linux


管理团队还没有达成一致意见?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP