📄 database.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -