database.java

来自「J2ME的手机游戏 马里奥版本的是男人就下一百层」· Java 代码 · 共 52 行

JAVA
52
字号
package Blocks;import java.io.IOException;import java.io.InputStream;import java.io.ByteArrayOutputStream;import javax.microedition.rms.*;public class Database {    public static final String DATABASE_NAME = "High Scores";    public RecordStore rs = null;    public boolean empty = true;    public static final int recordsNum = 6;    public static final int bufferSize = 20;    public Database() {        openDatabase();    }        private void openDatabase() {        try {            rs = RecordStore.openRecordStore(DATABASE_NAME, true);            if (rs.getNumRecords() > 0) {                empty = false;            } else {                populateDatabase();            }        } catch(RecordStoreException e){            e.printStackTrace();        }    }        public void closeDatabase(){        try{            rs.closeRecordStore();        } catch(RecordStoreException e){            e.printStackTrace();        }    }        private void populateDatabase(){        try{            fillText("/records.txt");        } catch( IOException e){            e.printStackTrace();        } catch( RecordStoreException e){            e.printStackTrace();        }    }        private void fillText(String fileName) throws IOException, RecordStoreException{        InputStream is = this.getClass().getResourceAsStream(fileName);        if(is != null){            ByteArrayOutputStream baos = new ByteArrayOutputStream();            //缂撳啿鍖

⌨️ 快捷键说明

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