I created my sales.dat with these code:
public static void main(String[] args) throws IOException {
DataOutputStream output = new DataOutputStream
(new FileOutputStream("E:/HOMEWORK/OOP/OOP-java/src/week2/sales.dat"));
output.writeChars("San Francisco: ");
output.writeDouble(1123.456);
}
And when I opened sales.dat, here it is:
I wrote another class to read .dat file:
public static void main(String[] args) throws IOException {
File file = new File("E:/HOMEWORK/OOP/OOP-java/src/week2/sales.dat");
FileReader reader = new FileReader(file);
char[] buffer = new char[4*1024];
int read = -1;
StringBuilder builder = new StringBuilder();
while( (read = reader.read(buffer)) !=-1){
builder.append(buffer,0,read);
}
System.out.println(builder);
//
}
And the result is :
So plz help me, the output must be :" San Francisco: 1123.456 "