
278 Chapter 7 • Securing Your Java Code
}
return out.toString();
}
public static void writeFile(String fileName, String contents) {
try {
FileOutputStream fo = new FileOutputStream(fileName);
DataOutputStream dOut = new DataOutputStream(fo);
dOut.writeChars(contents);
dOut.close();
} catch (IOException e) {
System.out.println("Error: " + e);
}
}
}
If we run this class normally, it will attempt to read the data from a
file called test.policy and output the contents to the screen. It will also
create a file called Test.txt and write a small phrase to the file.Try run-
ning this now, just to make sure that it has no problems reading and
writing to the disk. After you ...