Java 使用外部文本文件中的数据 [英] Java Use Data from External Text File

查看:32
本文介绍了Java 使用外部文本文件中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含前 1000 个素数的文本文件,我编写了一个方法来从所述文本文件中读取数据.

I have a text file containing the first 1000 prime numbers and I have written a method to read the data from said text file.

我想知道如何使用此文件中的数据并将其应用于另一种方法.

I would like to know how to use the data from this file and apply it to another method.

大致如下:

read data from file;
use first eight numbers and apply to this method;

任何帮助将不胜感激.

推荐答案

从文件中读取很简单,假设每个数字有一行 -

Reading from file is simple, assuming you have one line per number -

BufferedReader br = new BufferedReader(new FileReader("<your-text-file>"));
String txtNum;
while((txtNum = br.readLine()) != null)
{
   //txtNum is the number read, use it however you need
   if (txtNum.length() > 8) {
      thisMethod(txtNum.substring(0, 8));
   }
}

这篇关于Java 使用外部文本文件中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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