public class csv {
public static void main(String[] args)
{
FileReader fr = null;
File dir = new File("F:/log");
File[] files = dir.listFiles();
try
{
if(files != null)
{
for (int i = 0; i < files.length; i++)
{
String filePath = files[i].getAbsolutePath().toLowerCase().trim();
String filename=files[i].getName();
int startIndex = filename.lastIndexOf('.') + 1;
String fcsv = filename.substring(startIndex);
System.out.println( "fcsv :"+fcsv );
if(fcsv.equals("csv"))
{
System.out.println(filePath);
System.out.println( "filesName():"+filename );
fr = new FileReader(filePath);
//放到BufferedReader一筆筆讀出
BufferedReader br = new BufferedReader(fr);
ArrayList taglist = new ArrayList(getTagList(br));
for(int k=0; k<taglist.size(); k++)
{
System.out.println( k+":" );
System.out.println( ((String[])taglist.get(k))[0]);
System.out.println( ((String[])taglist.get(k))[1]);
System.out.println( ((String[])taglist.get(k))[2]);
System.out.println( ((String[])taglist.get(k))[3]);
System.out.println( "--------" );
}
br.close();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static ArrayList getTagList (BufferedReader br)
{
ArrayList taglist = new ArrayList();
String sData = null;
try
{
while ((sData = br.readLine()) != null)
{
String strArray[] = sData.split(",");
taglist.add(strArray);
}
}
catch (Exception e){
e.printStackTrace();
}
return taglist;
}
}
沒有留言:
張貼留言