import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.Timer; import java.util.TimerTask; public class ProgramB { public static void main(String[] args) throws IOException { Timer timer = new Timer(); //里面的run方法名是固定写法 TimerTask task = new TimerTask() { @Override public void run() { System.out.println("定时任务被执行了"); } }; timer.schedule(task,0, 1000); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader.readLine(); } }
标签:定时器,java,nio,new,io,使用,import,public From: https://www.cnblogs.com/nanfei/p/17047261.html