Java输入输出解决算法问题

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());
    }
}

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值