私はgroovyを初めて使用し、次の形式の入力ファイルから数値を読み取るためのプログラムを作成しています。
1
2 3
4 5 6
7 8 9 10
それらを2D配列に格納したいのですが、どうすればそれを実現できますか?
これまでのところ、readメソッドのコードは次のとおりです。
private read(fileName){
def count = 0
def fname = new File(fileName)
if (!fname.exists())
println "File Not Found"
else{
def input = []
def inc = 0
fname.eachLine {line->
def arr = line.split(" ")
def list = []
for (i in 1..arr.length-1) {
list.add(arr[i].toInteger())
}
input.add(list)//not sure if this is correct
inc++
}
input.each {
print it
//not sure how to reference the list
}
}
}
リストを印刷することはできますが、プログラムでリストのリストを使用する方法がわかりません(他の操作を実行するため)。誰かがここで私を助けてくれますか?