Goal: Get the data from a .dat file and print it to the console in Eclipse
Resources: fpfret.java and PointF.java and dichromatic.dat
I have resolved all my issues and have just a few console errors, here's my code and my question is: How do I add the getCodeBase() method?
package frp3;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.EOFException;
import java.net.URL;
import java.util.Vector;
public class FileRead {
public static void main(String[] args) { //getDocumentBase
System.out.println(readDataFile(getCodeBase() + "dichromatic.dat", 300, 750));
}
private static String getCodeBase() {
// TODO Auto-generated method stub
return null;
}
@SuppressWarnings("unchecked")
private static PointF[] readDataFile(String filename, int min, int max) {
@SuppressWarnings("rawtypes")
Vector v = new Vector();
try {
DataInputStream dis = new DataInputStream(new BufferedInputStream((new URL(filename)).openStream()));
float f0, f1;
while (true) {
try {
f0 = dis.readFloat();
f1 = dis.readFloat();
if (min < 0 || max < 0 || (f0 >= min && f0 <= max)) {
v.addElement(new PointF(f0, f1));
}
}
catch (EOFException eof) {
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
PointF[] array = new PointF[v.size()];
for (int i = 0; i < v.size(); i++) {
array[i] = (PointF) v.elementAt(i);
}
return array;
}
}
Here's my console errors:
java.net.MalformedURLException: no protocol: nulldichromatic.dat
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at frp3.FileRead.readDataFile(FileRead.java:27)
at frp3.FileRead.main(FileRead.java:12)
[Lfrp3.PointF;@29be513c
Here's my Project View in Eclipse: