![](/img/trans.png)
[英]how do I extract Name and Value from a line of text while reading from a file using Java?
[英]How do I convert rows as columns while reading from a file?
我如何閱讀和轉換下面的文件流
0101011110
0000011010
0000001011
1000011000
寫如下;
0001
1000
0000
1000
0000
1101
1111
1000
1110
0010
ArrayList不符合我的要求,經過幾次試驗后崩潰了。
我的文件中有10萬行40列。 在逐行讀取字符串之后,我不知道該怎么做新手我試過這個:
ArrayList<String> list=new ArrayList<String>();
String sequence;
while((sequence= instream.readLine())!= null) {
list.add(sequence);
}
Iterator<String> it=list.iterator();
for(int i=0; i<40; i++){
while(it.hasNext()){
String temp= it.next();
outstream.write(temp.charAt(i)+" ");
}
outstream.newLine();
}
這樣就可以了!
List<String> list = new ArrayList<String>();
String sequence;
while ((sequence = instream.readLine()) != null)
list.add(sequence);
for (int i = 0; i < 40; i++) {
for (String item : list) {
outstream.write(item.charAt(i) + " ");
}
outstream.newLine();
}
我會按以下步驟執行此操作:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.