parseInt函数

在这里插入图片描述
貌似遇到问题了,在Java中,parseInt方法是java.lang.Integer类的一个静态方法,它用来将字符串转换为基本数据类型int。如果字符串不能被解析为有效的整数,parseInt会抛出一个NumberFormatException。
原来是取整串转换,以为是取第一个字符,
所以这里需要分割字符串函数split或者转换为数组,
采用第二种结果
应用于个人项目:

public static void inHistryWork() {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream("src\\Io\\histrywork.ser");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
        while (true) {
            try {
                String line = reader.readLine();
                if (line == null) break;
                //String num= Arrays.toString(line.split("\\s+"));
                char[] chars = line.toCharArray();
                int a = Integer.parseInt(chars[0] + "");
                histryworkmap.put(a - 1, line);
                //Byte [] bytes=new Byte[1024];
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                break;
            } catch (IOException e) {
                e.printStackTrace();
                break;
            }
        }
    }

相关推荐

  1. Integer.parseInt

    2024-06-07 14:46:04       11 阅读
  2. praseInt 和 逻辑或连用

    2024-06-07 14:46:04       30 阅读
  3. Js-字符串转数字详细规则-Number-parseInt-parseFloat

    2024-06-07 14:46:04       18 阅读
  4. 损失函数(目标函数

    2024-06-07 14:46:04       40 阅读
  5. 字符函数字符串函数

    2024-06-07 14:46:04       34 阅读
  6. Python函数——函数介绍

    2024-06-07 14:46:04       32 阅读
  7. linux | pause函数 、alarm函数、signal函数

    2024-06-07 14:46:04       35 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-07 14:46:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-07 14:46:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-07 14:46:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-07 14:46:04       20 阅读

热门阅读

  1. web前端三大主流框架

    2024-06-07 14:46:04       7 阅读
  2. 消息队列RabbitMQ

    2024-06-07 14:46:04       7 阅读
  3. C/C++ 检测文件是否存在的方法

    2024-06-07 14:46:04       6 阅读
  4. React@16.x(18)错误边界

    2024-06-07 14:46:04       9 阅读
  5. Linux QT和OpenCV冲突

    2024-06-07 14:46:04       7 阅读
  6. Taro(React)使用富文本编辑器Editor

    2024-06-07 14:46:04       8 阅读
  7. Mybatis动态SQL

    2024-06-07 14:46:04       7 阅读