⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 实现了一个由时间服务器
💻 JAVA
字号:
package dnsServer;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ServiceList list=Test.readUserListFromFile();
		System.out.println(list.getList().size());
		for(int i=0;i<list.getList().size();i++){
			System.out.println(list.getList().get(i).url+":"+list.getList().get(i).service+":"+list.getList().get(i).failNo);
		}
		//ServiceList list=new ServiceList();
		//Test.writeUserListToFile(list);
		
	}
	public static ServiceList readUserListFromFile(){
		ServiceList list=null;
		ObjectInputStream ois;
		FileInputStream fis = null;
		try {
			fis = new FileInputStream("serviceList.txt");
			ois=new ObjectInputStream(fis);
			Object obj=ois.readObject();
		   	list=(ServiceList)obj;   	
			ois.close();
			fis.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}finally{
			try {
				fis.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
	public static void writeUserListToFile(ServiceList list){
		ObjectOutputStream oos;
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream("bin\\serviceList.txt",false);
			oos = new ObjectOutputStream(fos);
			oos.writeObject(list);
			oos.flush();
			oos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			try {
				fos.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -