📄 bookmarklist.java
字号:
//BookmarkList.java//List of sites bookmarked by the user, derived from Listimport java.util.*;import java.io.*;public class BookmarkList extends List { public static final String BFILE = "bookmark.lis"; public BookmarkList() {//Constructor super(); readIntoList(); } public void add(String s) {//Overrides the add method in List super.add(s); writeToFile(); } public void startupAdd(String s) {//Adds bookmarks from the file into the list without writing to disk super.add(s); } //******************************************************************************** public void remove(String s) throws Exception {//Removes an item from the list WebNode holder = head; boolean isFound = false; if(isEmpty()) throw new Exception("记录为空"); else if ((holder.getURL()).equals(s)){ head = holder.getNext(); size--; writeToFile(); isFound = true; } else { while ((holder != null) && (!isFound)){ if ((holder.getNext().getURL()).equals(s)) { holder.setNext(holder.getNext().getNext()); isFound = true; size--; writeToFile(); } else{ holder = holder.getNext(); } } } if (!isFound) { throw new Exception("No match found!"); } }//******************************************************************************** private void writeToFile() {//将list写入 a file try { FileOutputStream fOut = new FileOutputStream(BFILE); for (WebNode x = head; x != null; x = x.getNext()) { fOut.write(x.getURL().getBytes()); fOut.write('\n'); } fOut.close(); } catch (Exception e) { new PopupDialog("文件错误", "不能写入文件"); } } private void readIntoList() {//从file里面读取list try { FileInputStream fIn = new FileInputStream(new File(BFILE)); byte bt[] = new byte[(int) (new File(BFILE)).length()]; fIn.read(bt); String s = new String(bt); StringTokenizer st = new StringTokenizer(s, "\n"); while(st.hasMoreTokens()) startupAdd(st.nextToken()); fIn.close(); } catch(Exception e) { } }//******************************************************************************** public String returnURL(int loc) { WebNode wn = head; for (int x = 0; x < loc; x++) wn = wn.getNext(); return wn.getURL(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -