您的位置:首页 > 运维架构 > Tomcat

往D:\\apache-tomcat-8.0.9\\webapps\\ROOT\\testlog\\ajax-1.txt下写内容

2016-09-29 14:45 190 查看
import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.IOException;

import java.text.SimpleDateFormat;

public class Main {
public static void writeTime(){

new Thread(new Runnable() {

@Override
public void run() {
while (true) {

try {
System.out.println("往D:\\apache-tomcat-8.0.9\\webapps\\ROOT\\testlog\\ajax-1.txt下写内容!");
           SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"); //定义想要的格式  
           String time = simpleDateFormat.format(System.currentTimeMillis()); 
           
File f = new File("D:\\apache-tomcat-8.0.9\\webapps\\ROOT\\testlog\\ajax-1.txt");
BufferedWriter bw = new BufferedWriter(new FileWriter(f, true));
bw.write(time);
bw.newLine();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}

try {
Thread.sleep(1000);    
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}
}).start();

}
 
public static void main(String[] args) {
/*int a=0,c=2;
do{
--c;
a=0-a;
a++;
System.out.println(c);
}while(a<0);*/

writeTime();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐