JAVA 檔案(TXT)讀取 一行/刪除空白列+ArrayList
JAVA 檔案(TXT)讀取 一行/刪除空白列+ArrayList<String>
public ArrayList<String> m_DataList;//http://n198862320.pixnet.net/blog/post/34593403-java—arraylist%E7%94%A8%E6%B3%95%E3%80%81%E8%88%87array%E7%9A%84%E5%B7%AE%E5%88%A5
m_DataList= new ArrayList<String>(); //指定是String的型態
m_DataList.clear();
public int readTxt2ArrayList(String StrDir,String StrFilename)//http://yhhuang1966.blogspot.tw/2014/03/java_3503.html
{
File sd=Environment.getExternalStorageDirectory();
StrFilename=sd.getPath()+”/”+StrDir+”/”+StrFilename;
m_DataList.clear();
if(checkFile(StrFilename))
{
try
{
FileReader fr=new FileReader(StrFilename);
BufferedReader br=new BufferedReader(fr);
String line;
while ((line=br.readLine()) != null)
{
if(line.length()>0)//不可是單純空白列
m_DataList.add(line);
}
}
catch (IOException e)
{
m_DataList.clear();
}
}
return m_DataList.size();
}