作者:
soracho (空)
2015-06-12 16:22:12不好意思,個人是第一次上來發問。
想請教各位,個人讀取出來的文件,在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