quote.java

来自「Typing fingers Typing programme」· Java 代码 · 共 25 行

JAVA
25
字号
import java.util.*;
import java.io.*;
/**	This class has a method that returns a quote selected randomly from the file quotes.txt.
*/
class Quote{
	byte b[];
	Quote(){
		File f=new File(System.getProperty("user.dir")+"/text/quotes.abc");
		try{
			FileInputStream fis=new FileInputStream(f);
			b=new byte[(int)f.length()];
			fis.read(b);
			fis.close();
		}catch(Exception e){System.out.println(e);}
	}
	public String getQuote(){
		StringTokenizer st=new StringTokenizer(new String(b),""+'\r',false);
		int count=st.countTokens();
		int r=(int)(Math.random()*count);
		String quote="";
		for(int i=0;i<=r;i++)
			quote=st.nextToken();
		return quote.substring(1,quote.length());
	}
}

⌨️ 快捷键说明

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