I am having problems accessing a text file. The text file is in the same directory as all the classfiles. I was having similar problem when using icons on buttons, but I solved that with getClass().getResource("filename").
I thought I could use the same thing for RandomAccessFile, but the constructor doesn't take URL object. So my code looks like this:
RandomAccessFile file = new RandomAccessFile(getClass().getResource("records.dat").toString(), "rw");
For some reason even if I use getClass().getResource("records.dat").toString() the path gets changed.
This is the error message:
java.security.AccessControlException: access denied (java.io.FilePermission http:\localhost\classpath\records.dat read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
at java.lang.SecurityManager.checkRead(SecurityManager.java:863)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:195)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:94)
at Account.openFile(Account.java:93)
at Account.checkName(Account.java:106)
at BlackJack.showDialog(BlackJack.java:116)
.....
If I just do System.out.println(getClass().getResource("records.dat").toString() ) the result is:
http://localhost/classpath/records.dat which is quite different from what shows in the error message:
http:\localhost\classpath\records.dat
Can anybody tell me what the problem is?
Thank You