randomlong.java
来自「发布/订阅系统路由重配算法,可应用于ad hoc环境」· Java 代码 · 共 61 行
JAVA
61 行
package util;import java.io.*;public class RandomLong { static String randomFile = "random"; static String positionFile = "position"; static int pos; /** * @param args */ public static void main(String[] args) { LineNumberReader posIn; PrintWriter posOut; BufferedInputStream bytes; String line; int b; long l; // TODO Auto-generated method stub try{ posIn = new LineNumberReader(new FileReader(positionFile)); line = posIn.readLine(); pos = Integer.parseInt(line); posIn.close(); // overread the first pos bytes bytes = new BufferedInputStream(new FileInputStream(randomFile)); for(int i=0; i<pos; i++){ bytes.read(); } l = 0; for(int i=0; i<8; i++){ l = l << 8; b = bytes.read(); if(b==-1){ throw new IllegalStateException("EOF reached."); } l = l | b; } pos += 8; posOut = new PrintWriter(new FileWriter(positionFile),true); posOut.println(pos); System.out.println("N盲chster Long: "+l); }catch(Exception e){ System.err.println(e); e.printStackTrace(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?