Java: 使用 FileReader 编程

Java: Program with FileReader

尽我所能,我想不出如何解决这个程序。对于它的俗气,我深表歉意,我是一名学习 java 的学生,并且将其作为练习。

Lixnor is a mutant space trader in the Andromeda IV galaxy. He is low on 
supplies and funds and has trouble paying for the fuel that his ship 
requires. Every SGW (Standard Galactic Week) his partner, Ronxil gives him 
the coordinates for 2 valuable lost crates floating in space. The 
coordinates are sent in a file named "Coordinates.txt". The files always 
have 3 lines, each line containing a coordinate in the format (x,y,z) where 
x,y,z are integers. Due to Lixnor's lack of funds, he must first calculate 
whether it would be worth it for him to go pick them up. The first 
coordinates given are Lixnor's current coordinates, and the next two are the 
coordinates of the two crates. Lixnor must pick them up, then return to his 
original location. Write a program for Lixnor that calculates the distance 
he must travel in order to pick up the crates and return to his original 
position.

(24,-34,46)

(1,2,3)

(123,-1,0)

具体来说,我无法让 Java 读取文件。任何帮助都会很棒!

查看 Files.readAllLines 的 javadoc。

Path path = Paths.get(".... .txt");
List<String> lines = Files.readAllLines(path); // Using UTF-8

这是其中一种可能。处理由您决定。

读取文件很简单

  • 使用File file = new File(String fileAddress);
  • 获取文件实例
  • 现在使用Scanner scanner = new Scanner(file);读取文件。

继续并向我们展示工作以获得进一步的帮助。

我同意@ImGeorge 的观点,即在进行这项工作之前了解有关文件的一些基本知识 Reader。

在 SO,我们不能没有代码。