Jana Oliva

Greenhorn
+ Follow
since Feb 17, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jana Oliva

Could I get some code example, please. I thought that any code can access anything if it is in the same directory. The file will be eventually on the server, but now I just need to test it on the local machine. I am not doing any sockets or synchronization for now.
Even if I use the URLConnection how does it then tie together with the RandomAccessFile constructor, which takes either a String, or File? Because that is where I am getting the run time error.
Could I maybe get some code example of what you have in mind? Maybe I should just do database. The problem is that I just have a free hosting and don't have my own domain and therefore all the blows and whistles.
Thanks anyway.
20 years ago
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
20 years ago