Here's a sample for you to peruse...
import java.io.*;
public class parseCSV {
public static void main(String args[]) throws IOException {
String thisLine;
String[] fullText = new String[100]; //number of possible lines in your file
int counter = 0;
String fName = "<your *.csv file>";
FileInputStream fis = new FileInputStream(fName);
DataInputStream myInput = new DataInputStream(fis);
while ((thisLine = myInput.readLine()) != null) {
System.out.println("------
int sPos = 0;
int ePos = 1;
int tDelim = 0;
String d = "";
int colCount = 0;
int collCount = 0;
boolean fMe = false;
boolean finalCol = false;
while ( ePos < thisLine.length()) {
sPos = thisLine.indexOf(",", ePos);
tDelim = thisLine.indexOf(",\"", ePos);
if (tDelim == ePos) {
fMe = true;
collCount = ePos + 1;
while (collCount <= thisLine.indexOf("\",")) {
collCount += 1;
}
colCount += 1;
sPos = collCount;
}
if (colCount == 47) { //Get Max count of columns
finalCol = true;
collCount = ePos + 1;
while (collCount <= thisLine.lastIndexOf("\"")
collCount += 1;
}
colCount += 1;
sPos = collCount;
}
if (sPos == -1) {
d = thisLine.substring(ePos,th
System.out.println(d);
break;
}else if(ePos == 1) {
d = thisLine.substring(ePos-1,
System.out.println(d);
}else{
if (fMe) {
d = thisLine.substring(ePos + 1, sPos);
fMe = false;
}else if (finalCol) {
d = thisLine.substring(ePos, sPos);
finalCol = false;
}else{
d = thisLine.substring(ePos, sPos);
}
System.out.println(d);
}
colCount += 1;
ePos = sPos + 1;
}
counter++;
fullText[counter] = thisLine;
System.out.println("\nEnd Parsing\n-----------------
}
}
}
Main Topics
Browse All Topics





by: webwyzsystemsPosted on 2008-12-22 at 22:44:23ID: 23231722
Sorry, can't realistically be done. Javascript is not permitted to interact with the local file system.
If you are providing the CSV file ....You would be better off using PHP to read the file, then just write out the Javascript array. You would have to use php though....