小问题,望帮忙解决 现在有一个文件如下:1 2 11 3 21 6 15 6 22 3 22 6 22 4 21 5 21 4 34 5 32 5 33 5 33 6 3小弟想把这些数据按列读到3个数组中去,望大虾帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 说下大致思路,读文件到字符串中,然后以换行符进行split,得到的每个字符串再按空格split,用两重循环进行数组写入。 import java.io.BufferedReader;import java.io.File;import java.io.FileReader;public class Test { public static void main(String[] args) { File file = new File("E:\\test.txt"); String[] arr1=new String[13]; String[] arr2=new String[13]; String[] arr3=new String[13]; try{ if (file.exists()) { BufferedReader br = new BufferedReader(new FileReader(file)); String temp = null; int i =0; temp = br.readLine(); String[] tempArr=new String[3]; while (temp != null) { tempArr = temp.split(" "); arr1[i]=tempArr[0]; arr2[i]=tempArr[1]; arr3[i]=tempArr[2]; temp = br.readLine(); i++; } } }catch(Exception ex){ ex.printStackTrace(); } for(int j=0 ; j<arr1.length;j++){ System.out.print(arr1[j]+","); System.out.print(arr2[j]+","); System.out.print(arr3[j]+","); System.out.println(); } }} 求助:求一个不定数组中的最小值 如何阅读理解JAVA API文档呢? 关于Scanner 类的问题!急! java如何解析XML文件?如何提取其中的各个元素? validator-rules 的添加 高手请进~ 急! linux 下的java class path 问题 为jdbc.mssql抓狂!! fdafa 请看下例中ResourceBundle.getBundle("forms")什么意识?请教高手. applet连接数据库(SQL Server),在本机可读出内容,在别的机子上却看不到? String 转DTAE 问题 如何将输入Reader流的数据读取到char数组中?
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;public class Test { public static void main(String[] args) {
File file = new File("E:\\test.txt");
String[] arr1=new String[13];
String[] arr2=new String[13];
String[] arr3=new String[13];
try{
if (file.exists()) {
BufferedReader br = new BufferedReader(new FileReader(file));
String temp = null;
int i =0;
temp = br.readLine();
String[] tempArr=new String[3];
while (temp != null) {
tempArr = temp.split(" ");
arr1[i]=tempArr[0];
arr2[i]=tempArr[1];
arr3[i]=tempArr[2];
temp = br.readLine();
i++;
}
}
}catch(Exception ex){
ex.printStackTrace();
}
for(int j=0 ; j<arr1.length;j++){
System.out.print(arr1[j]+",");
System.out.print(arr2[j]+",");
System.out.print(arr3[j]+",");
System.out.println();
}
}}