📄 serverio.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 + -