简体   繁体   English

在Java中使用ReadFile方法需要帮助吗?

[英]Need assistance with ReadFile method in java…?

I'm stuck with this question and was hoping to get help here. 我对此问题感到困惑,并希望在这里获得帮助。 I just need to know how to get started because that's what I'm stuck on. 我只需要知道如何入门,因为这就是我坚持的目标。

Here's the question: 这是问题:

Assume file employees.txt exists and has the following format: name id number gross pay Write method readFile. 假设文件employee.txt存在并且具有以下格式:名称ID号总薪水写入方法readFile。 readFile accepts an id number, searches file, employees.txt, for the employee with that id number, and returns their gross pay. readFile接受一个I​​D号,搜索具有该ID号的员工的文件employee.txt,并返回其工资总额。

here you can see the basic steps. 在这里您可以看到基本步骤。

1.First create a File object like this: 1.首先创建一个File对象,如下所示:

File myfile = new File("path of the particular file");

2.Create FileReader object and give the created myfile object as a parameter. 2.创建FileReader对象,并将创建的myfile对象作为参数。

FileReader fr = new FileReader(myfile);

3.Make buffered reader object. 3.制作缓冲的读取器对象。

BufferedReader br = new BufferedReader(fr);

4.now you can read the file line by line and put it into a string as like below. 4.现在您可以逐行读取文件并将其放入字符串,如下所示。 String str = br.ReadLine(); System.out.println(str);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM