我有一個類似於此文本處理
12345 one
12345 two
12345 three
.......
問題文件是我怎麼可以得到所有的值從第二排,並將它們存儲在一個String [] 我知道如何在Java中讀取文件只是不知道如何削減第二行
我有一個類似於此文本處理
12345 one
12345 two
12345 three
.......
問題文件是我怎麼可以得到所有的值從第二排,並將它們存儲在一個String [] 我知道如何在Java中讀取文件只是不知道如何削減第二行
你可以用新行分割文件行。
String [] names = fileString.split("\n");
商店每行從文件到ArrayList<String>
,其比String[] array
更加靈活。
2.然後訪問你需要get()
方法的ArrayList
例如行:
ArraList<String> arr = new ArrayList<String>();
//Now add each lines into this arr ArrayList
arr.get(1); // Getting the Second Line from the file
`
確定這是我做的,但它跳過第一行
FileInputStream fstream = new FileInputStream("/sys..........");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
strLine = br.readLine();
while ((strLine = br.readLine()) != null) {
delims = strLine.split(" ");
first = delims[1];
where.add(first);
}
in.close();
從上面的例子中它只包含「two」和「three」
沒關係我有strLine = br.readLine()兩次 – pedja 2012-08-11 09:49:30
你可以做這樣的事情http://stackoverflow.com/a/285745/584026,然後得到第二個元素('array [1]' ) – ProfSmiles 2012-08-11 09:35:01