java写时间程序_java编写将本程序的次数,上次运行程序的时间,上次运行的操作系统信息写入文件中...

代码:

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FileReader;

import java.io.PrintWriter;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Properties;

public class 实战4 {//类名为中文是可以的

//计数器,将运行程序的次数,上次运行程序的时间,用户上次运行的操作系统写入文本文件中。()

private static String input;

private static int count;

private static String time;

private static String information;

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

File file = new File("C:\\Users\\lenovo\\Desktop\\count.txt");

if(!file.exists()){

file.createNewFile();

}

//count= time=

FileInputStream fis = new FileInputStream(file);

byte[] buffer = new byte[1024];

int length;

while((length=fis.read(buffer))!=-1){

input = new String(buffer,0,length);

}

if(input==null||input.trim().equals("")){

count = 0;

}else{

String[] arr = input.split(";");

count = Integer.parseInt(arr[0].substring(6, arr[0].length()));

System.out.println("上次程序运行的次数:"+count);

time = arr[1].substring(5, arr[1].length());

System.out.println("上次程序运行的时间:"+time);

System.out.println(arr[2]);

}

fis.close();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ss hh:mm:ss");

String time = sdf.format(new Date());

//获得系统的相关信息

Properties properties = System.getProperties();

String osName = properties.getProperty("os.name"); //操作系统名称

String osArch = properties.getProperty("os.arch"); //操作系统构架

String osVersion = properties.getProperty("os.version"); //操作系统版本

PrintWriter pw = new PrintWriter(file);

count++;

pw.write("count="+count+";");

pw.write("time="+time+";");

pw.write("information="+osName+" "+osArch+" "+osVersion);

pw.close();

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值