
-----------------------------------
wonsleved
Sun Dec 03, 2006 3:44 pm

read and write files
-----------------------------------
Hey, im having a problem with writing and reading data to a file. my code seems to work fine when im running it in eclipse, but when i try and run the html file it cant read or write anything. plz help.

-----------------------------------
cool dude
Sun Dec 03, 2006 4:34 pm


-----------------------------------
can you post your code and the html file please. Are you sure your saving the html file in the same folder as your program? what is the error message?

-----------------------------------
wonsleved
Sun Dec 03, 2006 9:05 pm


-----------------------------------
yeah its in the same folder. there is no error at all when im running it in eclipse, and when i run it in html it doesnt show an error, it just doesnt work, if i try writing to a file there will be nothing inside of it. someone told me that applets just dont have the capability of writing to a file in html but im reluctant ro believe that.
//sample writing code

try		
{
       PrintWriter pWriter = new PrintWriter(new FileWriter("save1.txt"));
       pWriter.println("" + randomInteger);
       pWriter.flush();
       pWriter.close();

} 
catch(Exception e)
{
}
//sample reading code

BufferedReader fReader;
String buf = "";
try
{
			
	fReader = new BufferedReader(new FileReader("save1.txt"));
        buf = fReader.readLine();
	randomInteger = (Integer.parseInt(buf));

}
fReader.close();
//HTML code





-----------------------------------
gsquare567
Sun Dec 03, 2006 9:17 pm


-----------------------------------
a) ur forgetting a second catch statement, and b) looks like all that does is rewrite the first line in the file :S

-----------------------------------
wonsleved
Sun Dec 03, 2006 9:24 pm


-----------------------------------
yeah sorry i was kinda rushing when i wrote that, and its just samples of code of what it will do, im just trying to show what i used in my program.
//sample writing code
try
{
PrintWriter pWriter = new PrintWriter(new FileWriter("save1.txt"));
pWriter.println("" + randomInteger);
pWriter.flush();
pWriter.close();

}
catch(Exception e)
{
}
//sample reading code

BufferedReader fReader;
String buf = "";
try
{

fReader = new BufferedReader(new FileReader("save1.txt"));
buf = fReader.readLine();
randomInteger = (Integer.parseInt(buf));
fReader.close(); 

}
catch(Exception e)
{
}

-----------------------------------
wtd
Mon Dec 04, 2006 12:38 am


-----------------------------------
Please use code tags in the future.

-----------------------------------
wtd
Mon Dec 04, 2006 12:40 am


-----------------------------------
a) ur forgetting a second catch statement

A try block may be used without an accompanying "catch."  Whether or not there's any point is a whole other matter.

I should note that the use of catch is extremely ill-advised.  It is bad to silently dismiss exceptions.

-----------------------------------
cool dude
Mon Dec 04, 2006 3:08 pm


-----------------------------------
a) ur forgetting a second catch statement

A try block may be used without an accompanying "catch."  Whether or not there's any point is a whole other matter.

I should note that the use of catch is extremely ill-advised.  It is bad to silently dismiss exceptions.

I second that! There is no point of catching an error if your not going to do anything about it. Your better off using throws Exception which may i add is just as bad.

-----------------------------------
wonsleved
Mon Dec 04, 2006 4:05 pm


-----------------------------------
okkk so what should i write instead

-----------------------------------
wonsleved
Mon Dec 04, 2006 4:22 pm


-----------------------------------
ok i output the error onto the scree, (thanks for tellin me to do that), and it said java.security.AccessControlException. whats that mean and how do i get rid of it?

-----------------------------------
wtd
Mon Dec 04, 2006 4:27 pm


-----------------------------------
Use the documentation.  It is your friend.

http://java.sun.com/j2se/1.4.2/docs/api/java/security/AccessControlException.html

-----------------------------------
wonsleved
Mon Dec 04, 2006 4:40 pm


-----------------------------------
i looked over that sight, but it only tells you what it is, how would u use it, or modefy it, or something to help get permission

-----------------------------------
Aziz
Tue Dec 05, 2006 9:23 am


-----------------------------------
 This exception is thrown by the AccessController to indicate that a requested access (to a critical system resource such as the file system or the network) is denied.

The reason to deny access can vary. For example, the requested permission might be of an incorrect type, contain an invalid value, or request access that is not allowed according to the security policy. Such information should be given whenever possible at the time the exception is thrown.

That means you can't access the file. You don't have permission to. Like trying to modify something in the school's computers. Why you don't have permission beats me, though.

-----------------------------------
wonsleved
Tue Dec 05, 2006 3:34 pm


-----------------------------------
so if i cant get the permission to read and write files, then is there any way i could step around that?
