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

📄 serverio.java

📁 JAVA实现的聊天工具,可以容纳最多10个用户 1.本系统需要JDK1.5 或更高版本的支持。 2.serverDatabase为服务器端的数据文件. 若使用现有数据,可用帐号:1, 密码
💻 JAVA
字号:
//to write and read object of ServerDatabase from a file
import java.io.*;
//import java.net.*;
public class ServerIO{
	private static ObjectOutputStream oos=null;
	private static ObjectInputStream ois=null;
		
	private static String file="serverDatabase";
			
	static void writeServerDatabase(ServerDatabase end){
		
		try{
			/*BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file));
			oos=new ObjectOutputStream(bos);*/
			oos=new ObjectOutputStream(new BufferedOutputStream(
					new FileOutputStream(file)));
			oos.writeObject(end);
			//bos.flush();
			oos.flush();
			oos.close();
		}catch(IOException e){
			System.out.println(e+" "+e.getMessage());
		}
	}
	
	static ServerDatabase readServerDatabase(){
		
		try{
			/*BufferedInputStream bis=new BufferedInputStream(new FileInputStream(file));
			ois=new ObjectInputStream(bis);*/
			ois=new ObjectInputStream(new BufferedInputStream(
					new FileInputStream(file)));
			return (ServerDatabase)ois.readObject();
		}catch(Exception e){
			System.out.println(e+" "+e.getMessage());
			return null;
		}
	}
	
	static boolean checkFile(){ // to check if none of data has been written in
		File temp=new File(file);
		boolean signal=temp.exists();
		if(!signal) //file doesn't exit,the initial status
			return false;
		else return true;
	}
	
	static int getInt() throws IOException{
		return Integer.parseInt(getString());
	}
	
	static long getLong() throws IOException{
		return Long.parseLong(getString());
	}
	
	static String getString() {
		BufferedReader br; 
		br=new BufferedReader(new InputStreamReader(System.in));
        try{
        	return br.readLine();
        }catch (IOException e){
        	System.out.println(e+" "+e.getMessage());
        	return null;
        }
	}		
}

⌨️ 快捷键说明

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