如何从文本文件读取整数值 [英] How to read integer values from text file

查看:60
本文介绍了如何从文本文件读取整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
Java:将文件中的整数读取到数组中

我想从一个文本文件(例如contactids.txt)读取整数值.在文件中,我的值是

I want to read integer values from a text file say contactids.txt. in the file i have values like

12345
3456778
234234234
34234324234

我想从文本文件中读取它们...请帮助

i Want to read them from a text file...please help

推荐答案

您可能想做这样的事情(如果您使用的是Java 5及更高版本)

You might want to do something like this (if you're using java 5 and more)

Scanner scanner = new Scanner(new File("tall.txt"));
int [] tall = new int [100];
int i = 0;
while(scanner.hasNextInt())
{
     tall[i++] = scanner.nextInt();
}

通过 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆