Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Question about Java File

  Asked By: Brooklyn    Date: Oct 26    Category: Java    Views: 469
  

I have a Java program
where I Am trying to write data into the file. I am using follwing
code and when I use it I get error says "access denied(
java.io.FilePermission Loginfo.out write )"


Here is the code
import java.io.*;
import java.util.Date;

public class SaveDate {

public static void main(String argv[]) throws Exception {
FileOutputStream fos = new FileOutputStream("date.out");
ObjectOutputStream oos = new ObjectOutputStream(fos);
Date date = new Date();
oos.writeObject(date);
oos.flush();
oos.close();
fos.close();
}
}

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Laurel Collins     Answered On: Oct 26

Can you create a file  manually in the same directory? Your code
works fine for me. If you are using Windows, try the following in a
command window:

dir > list.txt

If Linux:

ls > list.txt

If the appropriate one works, you have write  permission in the
current directory.

I'm also curious about the error  message. It includes "Loginfo.out",
but your code shows "date.out". Are you sure you are running the
code you think you are running? Perhaps you have an old version of
SaveDate.class?

 
Answer #2    Answered By: Orville Rodriguez     Answered On: Oct 26

The reason I wasn to able to work because Applet does not allow
writign date  into a file. But there is a way to do that. I had to
modify my java.policy file. look this link this will give you more
info.
up.botik.ru/.../appA.html#FilePermission
pleaes let me knwo if you have any question.

 
Didn't find what you were looking for? Find more on Question about Java File Or get search suggestion and latest updates.




Tagged: