【问题标题】:Java: Program with FileReaderJava:使用 FileReader 编写程序
【发布时间】:2015-11-09 14:33:08
【问题描述】:

尽我所能,我不知道如何解决这个程序。我为它的俗气道歉,我是一名学习 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 读取文件。任何帮助都会很棒!

【问题讨论】:

  • 学习Java文件阅读器。尝试这样做,然后返回一些代码。那么我们可能会提供帮助。

标签: java file-io filereader


【解决方案1】:

读取文件很简单

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

继续向我们展示工作以获取更多帮助。

我同意@ImGeorge 的观点,即在做这项工作之前先了解一些关于文件阅读器的基本知识。

在 SO,如果没有代码,我们将无能为力。

【讨论】:

    【解决方案2】:

    查看Files.readAllLines的javadoc。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-16
      • 2019-03-29
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      相关资源
      最近更新 更多