Hi all. Learning Java - sorry for my stupidity if you see any.
Here is the code:
private static void readFile() throws Exception {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, DAYS);
String fOther = "filename.csv";
String fOtherImp = "filename_imp.csv";
LineNumberReader lineCounter = new LineNumberReader(
new InputStreamReader(new FileInputStream(fOther)));
String nextLine = null;
try {
while ((nextLine = lineCounter.readLine()) != null) {
if (nextLine == null)
System.out.printf("Null line");
continue;
}
if (lineCounter.getLineNumber() < 10001) {
BufferedReader br = new BufferedReader(new FileReader (fOther));
CsvWriter csvOutput = new CsvWriter(new FileWriter(fOtherImp, true), ',');
log.info("File is OK. Creating new import file.");
// Create Headers
csvOutput.write("Date");
csvOutput.write("Resort");
csvOutput.write("Source");
csvOutput.write("Medium");
csvOutput.write("Campaign");
csvOutput.write("Keyword");
csvOutput.write("Pageviews");
csvOutput.write("Unique Page");
csvOutput.write("Exits");
csvOutput.write("Time on Page");
csvOutput.write("Bounces");
csvOutput.endRecord();
-->
//String strLine;
String strLine = null;
String[] strLine1;
ArrayList<String> list = new ArrayList<String>();
while ((strLine = br.readLine()) != null) {
list.add(strLine);
}
for (int i = 0; i < list.size(); i++) {
Pattern p = Pattern.compile("(?<=[c|C]{2}\.)([0-9]+)?(?=\_.|.[html|xml])");
String row = list.get(i);
String col1 = row.split(",")[0];
String col2 = row.split(",")[1];
String col3 = row.split(",")[2];
String col4 = row.split(",")[3];
String col5 = row.split(",")[4];
String col6 = row.split(",")[5];
String col7 = row.split(",")[6];
String col8 = row.split(",")[7];
String col9 = row.split(",")[8];
String col10 = row.split(",")[9];
String col11 = row.split(",")[10];
if (row == null) {
System.out.printf("Null line");
continue;
}
String url = row.split(",")[1];
String resortid = new String();
//String result = new String();
Matcher m = p.matcher(url);
while (m.find()) {
resortid = m.group();
// Add Data
csvOutput.write(col1);
csvOutput.write(resortid);
csvOutput.write(col3);
csvOutput.write(col4);
csvOutput.write(col5);
csvOutput.write(col6);
csvOutput.write(col7);
csvOutput.write(col8);
csvOutput.write(col9);
csvOutput.write(col10);
csvOutput.write(col11);
csvOutput.endRecord();
}
---->
}
log.info(fOtherImp + " created.");
csvOutput.close();
} else {
log.error("File exceeded 10001 lines. File rejected");
}
} catch (Exception ex) {
log.error(ex);
//} catch (ArrayIndexOutOfBoundsException e) {
//log.error( "OutOfBounds: " + e.getMessage());
}
I think I know which part of the code (denoted by the --->) that is causing the problem. But I am missing something because of my lack of knowledge :(. Thanks for any info!