Java输入输出解决算法问题
Scanner和System.in在读取数据的时候会与硬盘IO进行交互,但是一次仅在硬盘中读取出一项数据,每次获取数据的时候都需要与硬盘IO进行交互,效率很慢
Java处理IO有两套标准
1.字节流
2.字符流
一般在硬盘中都是以字节流方式存储,将其转化为字符流后使用BufferedReader(带内存缓冲区的字符流)临时存储数据,直接在缓冲区中读取数据
import java.util.*;
import java.io.*;public class Main()
{
public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); public static Read in = new Read();
public static void main(String[] args)thorws IOExpection
{
//写代码
out.cloes();
}
}
Class Read//快速读
{
//字符串裁剪
StringTokenizer st = new StringTokenizer("");
//1.字节流->字符流
//2.带内存缓冲区的字符流
BufferedReader bf = new BufferedReader(new InputStream(System.in));
String next() throws IOExpection
{
while(!st.hasMoreTokens())
{
st = new StringTokenizer(bf.readLine());
}
return st.nextToken();
}
String nextLine() thorws IOExpection
{
return bf.readLine();
}
int nextInt() throws IOExpection
{
return Integer.parseInt(next());
}
long nextLong() throws IOExpection
{
return Long.parseLong(next());
}
double nextLong() throws IOExpection
{
return Double.parseDouble(next());
}
}