import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.List;
import java.util.Vector;
public class Numbers implements Runnable {
private static int baseNumber;
private List<Integer> numberList;
private String path = "e:/number.txt";
public Numbers() {
// 构建一个
this.numberList = new Vector<Integer>();
this.CheckFile();
try {
DataInputStream read = new DataInputStream(new FileInputStream(
this.path));
baseNumber = read.readInt();
read.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void CheckFile() {
try {
File file = new File(this.path);
if (!file.exists()) {
file.createNewFile();
DataOutputStream write = new DataOutputStream(
new FileOutputStream(this.path));
write.writeInt(0);
write.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
public synchronized void getNumber() {
try {
baseNumber++;
this.numberList.add(baseNumber);
DataOutputStream write = new DataOutputStream(new FileOutputStream(
this.path, false));
write.writeInt(baseNumber);
write.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void ShowNumber() {
for (int i = 0; i < numberList.size(); ++i) {
int num = numberList.get(i).intValue();
System.out.print(num + "\t");
}
System.out.print("\n");
}
public void run() {
for (int i = 0; i < 10; ++i) {
getNumber();
}
this.ShowNumber();
}
public static void main(String[] args) {
Thread t1 = new Thread(new Numbers());
Thread t2 = new Thread(new Numbers());
t1.start();
t2.start();
}
}
分享到:
相关推荐
j2se 小程序源代码
j2se程序在MyEclipse下使用j2se程序在MyEclipse下使用j2se程序在MyEclipse下使用j2se程序在MyEclipse下使用j2se程序在MyEclipse下使用
(J2SE平台Java程序设计)阶段测试题,(J2SE平台Java程序设计)阶段测试题,(J2SE平台Java程序设计)阶段测试题,(J2SE平台Java程序设计)阶段测试题
其中有Java源代码,还有发布的程序,点击直接即可运行。对于J2SE的学习非常有帮助。
基于J2ME开发的聊天程序,使用socket,可与J2SE的程序连接,本人毕业设计的一部分,给做毕设的同学借鉴借鉴
这是我在学习J2SE的过程中编写的练习小程序,希望对java初学者能有帮助!
j2se内容,用java写的五子棋单机版,只是为双方提供一个平台,没有实现人机对弈功能。
这个Demo包括了J2SE在Oracle网站上全部的示例源代码
java开发的类似于记事本的应用程序,有文件,编辑,字体等功能
java概述 资源分为10章 本章为介绍JAVA 以及配置集成开发环境 PPT文件 技术性文件 后边会陆续上传
java基础 课件 实验程序源码 实验报告
Java j2se QQ 毕业论文
J2SE_API、J2SE_API、J2SE_API、J2SE_API、J2SE_API、J2SE_API、J2SE_API
Java-J2SE程序设计实训任务书.doc
推箱子游戏是j2se基础类知识的充分综合与应用,通过这个程序源码的学习,能更好的帮助我们掌握j2se基础的相关概念和各种类的使用
J2SE api开发文档。此文档对java程序员是不可或缺的。希望给需要的朋友带来帮助。
J2SE基础知识大全 J2SE基础知识大全 J2SE基础知识大全
zxing/zxing-j2se-1.7.jar包, 包含类 com.google.zxing.StringsResourceTranslator.class com.google.zxing.client.j2se.BufferedImageLuminanceSource.class ...
J2SE课件J2SE课件J2SE课件J2SE课件J2SE课件J2SE课件