我有文本文件内容,如
name1,name2,name3,....nameN
value1,value2,value3,....valueN
我希望内容是
name1 value1
name2 value2
name3 value3
. .
. .
nameN valueN
我怎样才能用java代码实现这一点。
我有文本文件内容,如
name1,name2,name3,....nameN
value1,value2,value3,....valueN
我希望内容是
name1 value1
name2 value2
name3 value3
. .
. .
nameN valueN
我怎样才能用java代码实现这一点。
String[] names = namesString.split(',');
String[] values = valuesString.split(',');
//usage
System.out.println(names[0] + " with value " + values[0];
String[] names = namesString.split(",");
String[] values = valuesString.split(",");
for(int i=0;i<names.length;i++){
System.out.println(names[i] + " " + values[i];
}
try {
File file = new File("D:\\temp\\test.txt");
InputStreamReader reader = new InputStreamReader(new FileInputStream(file));
BufferedReader bufferedReader = new BufferedReader(reader);
String namesString = bufferedReader.readLine();
String valuesString = bufferedReader.readLine();
String[] names = namesString.split(",");
String[] values = valuesString.split(",");
for (int i = 0; i < names.length; i++) {
System.out.println(names[i] + "\t" + values[i]);
}
bufferedReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}