public static void main(String[] args)
{
try
{
List<List<String>> csvLineList = readCSV("C:\\Users\\User\\Desktop\\addresses.csv");
if(csvLineList != null)
{
for(int i = 0; i < csvLineList.size(); i++)
{
for(int j = 0; j < csvLineList.get(i).size() - 1; j++)
{
System.out.print(csvLineList.get(i).get(j));
System.out.print(",");
}
if(csvLineList.get(i).size() - 1 > 0)
{
System.out.print(csvLineList.get(i).get(csvLineList.get(i).size() - 1));
}
System.out.println();
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static List<List<String>> readCSV(String path) throws Exception
{
List<List<String>> lineList = null;
BufferedReader br = null;
File csvfile;
String line;
List<String> tmpOneLine;
String[] tmpLineArr;
try
{
lineList = new ArrayList<List<String>>();
csvfile = new File(path);
br = new BufferedReader(new FileReader(csvfile));
while ((line = br.readLine()) != null)
{
tmpOneLine= new ArrayList<String>();
tmpLineArr = line.split(",");
tmpOneLine = Arrays.asList(tmpLineArr);
lineList.add(tmpOneLine);
}
}
catch (IOException ioEx)
{
throw ioEx;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (br != null)
{
br.close();
}
}
return lineList;
}
'Java' 카테고리의 다른 글
[ Java ] Swap 알고리즘 구현 (0) | 2021.10.25 |
---|---|
[ Java ] Crontab 기능 구현 (0) | 2021.05.12 |