Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java File

  Asked By: Jodon    Date: Sep 23    Category: Java    Views: 476
  

I have a question regarding File I/O. right now i am using
FileOutputStream("Text.txt") so it basically create a Text.txt file
in my mozilla directory. But I want to save this file in
C:\Test\Text.txt directory. Can anyone pleaes tell me how would I do
that.

Share: 

 

7 Answers Found

 
Answer #1    Answered By: Freya Brown     Answered On: Sep 23

File f = new File("c:\\test\\test.txt");
PrintWriter t = new PrintWriter (new FileWriter(f));

That is using the Java 1.1 io library. Just changr test.txt to
c:\\test\\text.txt

 
Answer #2    Answered By: Dep Tran     Answered On: Sep 23

Simply u can use / as the delimter cool

 
Answer #3    Answered By: Cesara Fernandez     Answered On: Sep 23

or you do it the right way: File.separator
This is platform independent. "\\" is windows 100%.
Don't do it this way.

 
Answer #4    Answered By: Daimon Jones     Answered On: Sep 23


Just use '\\' as the delimiter in the path and voila.. u can save  it on
any dir under sun..

 
Answer #5    Answered By: Aabirah Khan     Answered On: Sep 23

if you are using mozilla  i assume that you are using a applet. applets
cannot write anywhere. the applet needs permission, therefore you will
have to look at signing your applet or using access policies.

 
Answer #6    Answered By: Utsav Shah     Answered On: Sep 23

I do understand that applet cannot write into a file. But, as you
said if i give permission then it will. but, my question  is how can
i put some limitation. right now i am saying grant { permission
java.security.AllPermission; }; and this is able to write. But as you
can tell that this is very risky.... so, now i want to use put some
codebase of something like that. I am not much familer with the
security.. but if you do. pleaes let me know. Once Again, thanks you
very much for your help.

 
Answer #7    Answered By: Ziza Mizrachi     Answered On: Sep 23

i think you define the io in the grant line.

grant permission io.file or something. i was only interested in
granting to a socket io. sorry for long delay, i have been away.

have you found the answer yet?

i did a quick search on google

http://www.google.co.uk/search?q=java+policy+file+io&ie=UTF-8&oe=UTF-8&hl=en&btn\
G=Google+Search&meta=

and heres your line of interest from the first result

grant signedBy "Duke" {
permission java.io.FilePermission "/tmp/*", "read,write";
};

no rudeness intended, but it wasnt that hard.

I am sure substituting "/tmp/*" with "*" will work.

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




Tagged: