创建新文件、写入内容、获取上次修改时间

来源:互联网 发布:weex js service 编辑:程序博客网 时间:2024/05/17 02:02
/** *  */import java.io.File;import java.io.FileNotFoundException;import java.io.IOException;import java.io.RandomAccessFile;import java.text.SimpleDateFormat;import java.util.Date;/** * @author gabriel * */public class fileTest {public static void main(String[] args) {File file = new File("d:\\a\\cba.txt");try {RandomAccessFile ra = new RandomAccessFile(file,"rw");ra.writeBytes("hello、世界");long last = file.lastModified();Date date = new Date(last);SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(formater.format(date));} catch (FileNotFoundException e) {e.printStackTrace();} catch(IOException io){io.printStackTrace();}}}

原创粉丝点击