problem with file.
hey fellas!
In the code below I want from one file (that I call germanos.db) to get some values. But I had this error message when I run the program:
Exception in thread "main" java.lang.NullPointerException
at fixedLengthScanner.dbTest(Compiled Code)
at fixedLengthScanner.main(fixedLengthScanner.java:43)
If I remove the file then I have this message that is seems logical:
IOException error: germanos.db (No such file or directory)
My code is:
import java.io.*;
import java.util.*;
import java.util.Date;
import java.sql.*;
import java.sql.Types;
import java.text.*;
import java.net.*;
import java.lang.*;
import dk.digiquant.integration.*;
public class fixedLengthScanner
{
public int index=0;
public String s;
public fixedLengthScanner(String ss)
{
s = ss;
index = 0;
}
public String getField(int len)
{
String retStr = "";
try
{
retStr = s.substring(index, index+len);
index += len;
}
catch (IndexOutOfBoundsException ex)
{
System.out.println("Index out of bounds");
}
return retStr;
}
public static void main(String argv[]) throws Exception
{
//String theName = "arnaki aspro kai paxu" ;
fixedLengthScanner t = new fixedLengthScanner(null);
t.dbTest();
}
void dbTest() {
DataInputStream dis = null;
String dbRecord = null;
try {
File f = new File("germanos.db");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
while ( (dbRecord = dis.readLine()) != null) {
fixedLengthScanner fs = new fixedLengthScanner(dbRecord);
String INTContract_AID = fs.getField(8);
String F_INTService_AID = fs.getField(8);
String Update_Flag = fs.getField(1);
String Surname = fs.getField(60);
String Firstname = fs.getField(60);
String CompanyName = fs.getField(60);
String Fiscal_Code = fs.getField(30);
String FiscalAuthority = fs.getField(30);
String City = fs.getField(30);
String Address1 = fs.getField(60);
String Phone = fs.getField(30);
String FAX = fs.getField(30);
String BirthDate = fs.getField(8);
String ZipCode = fs.getField(15);
String Username_1 = fs.getField(48);
String Username_2 = fs.getField(48);
String Username_3 = fs.getField(48);
String Password = fs.getField(16);
String entry_Date = fs.getField(8);
String activation_Date = fs.getField(8);
String deActivation_Date = fs.getField(8);
String Comments = fs.getField(16);
System.out.println("end");
}
}catch (IOException e) {
System.out.println("IOException error: "+e.getMessage());
} finally {
if (dis != null) {
try {
dis.close();
} catch (IOException ioe) {
System.out.println("IOException error trying close the file: "+ioe.getMessage());
}
}
}
}
}

