Refresh Your Java - Before Java Interview
We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....
Own CSV Parser : This examples shows how to create a your own CSV parser.
This example
i) Reads a CSV File as Stream
ii)
Parses Data and create String[][]
import
java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import
java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import
java.io.Reader;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import
java.nio.channels.FileChannel;
import
java.nio.charset.Charset;
import
java.util.ArrayList;
public class OwnCSVParser {
public static String [][]
parseCSV(String classpathResourceString, char nHeaderLine){
InputStream inStream
= new
OwnCSVParser().getClass().getResourceAsStream(classpathResourceString);
InputStreamReader reader = new InputStreamReader (inStream);
return parseCSV (reader, nHeaderLine);
}
public static String [][]
parseCSV(Reader reader, char nHeaderLine){
BufferedReader br = new BufferedReader( reader );
String line=null;
List lineList = new ArrayList();
try {
line = br.readLine();
while ( (line = br.readLine()) != null ) {
lineList.add(line);
}
br.close();
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
int nLine = lineList.size();
int nRealLine = nLine-nHeaderLine;
if (nRealLine<=0) return null;
String [][] fields = new String [nRealLine][];
Iterator iter = lineList.iterator();
for (int i=0; i<nHeaderLine;i++){
iter.next();
}
for (int i=0; i<nRealLine; i++){
fields[i] =
((String)iter.next()).split(",");
}
return fields;
}
}
This Portal is intended to put all Java/J2ee related topics at one single place for quick referance, not only Technical , but also the Project Management Related thing such as Development Process methodoogies build process, unit testing etc.,
This Portal has More than 500 Java Interview Questions (also could be Considered as Quick Notes) very neatly separated topic by topic with simple diagrams which makes you easily understandable. Importantly these are from our Realtime expericance.