import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
class Sample {
public static void main(String args[]) {
try {
ArrayList<String> textLines = new ArrayList<String>();
boolean result = false;
result = readTextFileLines("sample.csv", textLines);
if (result == false) {
return;
}
if (textLines.size() % 2 == 1) {
textLines.add("");
}
int rowcount = textLines.size() / 2;
String[][] data = new String[rowcount][2];
for(int row = 0; row < rowcount; row++) {
data[row][0] = textLines.get(row * 2);
data[row][1] = textLines.get(row * 2 + 1);
}
for(int row = 0; row < data.length; row++) {
for(int col = 0; col < data.length; col++) {
System.out.println(data[row][col]);
}
}
} catch (Exception e) {
System.out.println(e);
}
}
public static boolean readTextFileLines( String filePath, ArrayList<String> textLines )
{
boolean result = false;
FileReader fr = null;
BufferedReader br = null;
try
{
fr = new FileReader( filePath );
br = new BufferedReader( fr );
String line = br.readLine();
while( line != null )
{
textLines.add( line );
line = br.readLine();
}
result = true;
}
catch( FileNotFoundException e )
{
System.out.println( e );
}
catch( IOException e )
{
System.out.println( e );
}
finally
{
try
{
if( br != null ) {
br.close();
}
else if( fr != null ) {
fr.close();
}
}
catch( IOException e )
{
System.out.println(e);
}
}
return result;
}
}