Date和Long之间互换,实现文件打开时间的的设置和获取
2015-03-03 15:57
323 查看
<pre name="code" class="java"><span style="font-family: Arial, Helvetica, sans-serif;">不出意外的话,代码应该如下,但是……</span>
事实告诉我们,正如方法名一样,<pre name="code" class="java">lastModified指的是上一次修改时间。这样,我们就想一个不影响原文内容,又可以改变修改时间的方法。。。
</pre><pre name="code" class="java"> time= file.lastModified(); SimpleDateFormatsdf= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); java.util.Datedt = new Date(time); StringsDateTime = sdf.format(dt); //得到精确到秒的表示:08/31/2006 21:08:00 file_lastmodified.setText("file_lastmodifiedtime:"+String.valueOf(time)+"===="+sDateTime); DatecurDate = new Date(System.currentTimeMillis());//获取当前时间 time3= curDate.getTime(); current_time.setText("currenttime:"+String.valueOf(time3)+"===="+sdf.format(curDate)); file.setLastModified(time3); time = file.lastModified(); SimpleDateFormat sdf= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); java.util.Date dt = new Date(time); String sDateTime = sdf.format(dt); //得到精确到秒的表示:08/31/2006 21:08:00 file_lastmodified.setText("file_lastmodifiedtime:"+String.valueOf(time)+"===="+sDateTime);
</pre><pre name="code" class="java">
解决方案:
采用一个文件追加的方式来添加内容,当然,只是添加一个“”,也就是空,这样就能实现我们要的效果啦
</pre><pre name="code" class="java"> BufferedWriter out = null; try { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true))); out.write(""); } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } }
相关文章推荐
- 文件磁盘相关函数[14]-获取文件的创建时间 FileAge; FileDateToDateTime
- Datediff函数 助你实现不同进制时间之间的运算
- 创建一个Date.text文件,获取当前的日期,将日期格式为“2013/02/14 05:20:00”的形式。然后一秒钟记录一次,将新的时间存入到文件中。
- java实现记事本基本功能:新建、打开、保存、另存为、退出、替换、全部替换、复制、剪切、粘贴、全选、获取当前时间日期、修改字体、颜色、自动换行等
- IntelliJ IDEA设置Tabs实现同时打开多个文件且分行显示
- pb9获取文件创建时间、最后修改时间及设置最后修改时间的方法
- js获取时间并实现字符串和时间戳之间的转换
- 让自己的软件实现双击打开文件(修改注册表设置关联)
- Eclipse配置skpet实现代码提示,并设置js文件的默认打开方式
- SDK获取、设置文件属性和时间
- js获取时间并实现字符串和时间戳之间的转换
- ResultSet 获取Date时间,SQL语句设置时间
- java设置一段代码执行的超时时间的简单方法 间接实现获取Connection超时问题
- 获取 设置文件时间
- java设置一段代码执行的超时时间的简单方法 间接实现获取Connection超时问题
- [WinAPI] API 14 [获取、设置文件属性和时间]
- 修改JFileChooser对话框风格,设置打开对话框的默认文件名,获取改变路径之后的文件保存路径
- JS中的与时间相关的函数(long与date,timestamp之间的转换)
- Golang 奇葩的时间包之Json与struct对象之间互相转换,JsonDate和JsonTime自定义类型如何实现json编码和解码(二)
- 点击 TextView 弹出 时间设置框 DatePicker 、 DatePickerDialog,用于Sqlite db 获取数据