不好意思,个人是第一次上来发问。
想请教各位,个人读取出来的文件,在Data[0][0]的第一个字是?呢。
程式码:
package readCSVtoArray;
import java.io.BufferedReader;
import java.io.FileInputStream;
//import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class readCSVtoArrayData
{
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
String fileUrl="d:/eclipse-java-luna-SR1a-win32-x86_64/eclipse/info.csv";
InputStreamReader isr = new InputStreamReader(new FileInputStream(fileUrl),
"utf-8");
BufferedReader br = new BufferedReader(isr);
String str = null;
String Data[][];
ArrayList tmpxList = new ArrayList(); //分成两个Arraylist存 X跟Y
ArrayList tmpyList = new ArrayList();
ArrayList tmpList = new ArrayList();
//int num = 0;
while((str = br.readLine())!= null)
{
String tempArray[] = str.split("\\,");//分割空白键
tmpxList.add(tempArray[0]);
tmpyList.add(tempArray[1]);
}
//产生二维阵列, 依据暂存的size(txt档的行数)
Data = new String [tmpxList.size()][2];
for(int i = 0; i< tmpxList.size(); i++)
{
//这段让我知道不能直接用list条数
Data[i][0] = (String) tmpxList.get(i);
Data[i][1] = (String) tmpyList.get(i);
}
for(int i = 0; i < Data.length; i++)
{
for(int j = 0; j < Data[0].length; j++)
{
System.out.print(" "+Data[i][j] + " ");
}
System.out.println();
}
System.out.println();
System.out.print(" "+tmpList+ " ");
//System.out.println();
//System.out.print(" "+tempArray[0][1] + " ");
}
}
Java与Txt档案在此:http://4fun.tw/asmp