好吧,这是我的问题。我写了一个算法来完成特定的事情。目前,我自己在类构造函数中创建进程并将它们存储在优先级队列中。但是我希望能够编写一个包含多行的 .txt 文件。每行代表一个进程,其不同属性由空格分隔。我的 .txt 如下所示:
P1 0 8
P2 1 4
P3 2 9
P4 3 3
END 4 9999
p1、p2...等是每个进程的名称。那么第二列是第一个属性,第三列是第二个属性。
我需要能够一次读取每一列并将值存储在我的进程中。我如何读取这些值并区分它们? (将它们视为单独的事物)
最佳答案
所以您想逐行读取文件并将每一行分开?
BufferReader in=new BufferedReader...
String line;
while ((line=in.readLine())!=null) {
String[] data=line.split(" ");
//now, data will be a array which contains the data
//data[0] = the first item in the line
//data[1] = the first number
//data[2] = the second number
}
关于java bufferedReader.如何读取一行中的部分内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29583385/