TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG-DEVEL:227] file stuff



My appologies that this is so late.

I didn't see an answer to this question so here is mine.

Creating a File object does not create the file.  You will need to call
the createNewFile() method on the File object that you created.

Alternately, I believe you could use the RandomAccessFile with mode
"rw" and that would create the file automatically.  It might also be
easier to use.

Bill

--- Erick Stohr <erick@pagelab.net> wrote:
> Here is my code, I am trying to create a new file and write it to a
> specific diretory and am getting file
> 
> java.io.FileNotFoundException: /home/es/java/filename.htm (Permission
> denied)
>  at java.io.FileOutputStream.open(Native Method)
>  at java.io.FileOutputStream.<init>(FileOutputStream.java:98)
>  at java.io.FileOutputStream.<init>(FileOutputStream.java:58)
>  at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
> java.io.FileNotFoundException: /home/es/java/phrase_word1.htm
> (Permission denied)
>  at java.io.FileOutputStream.open(Native Method)
>  at java.io.FileOutputStream.<init>(FileOutputStream.java:98)
>  at java.io.FileOutputStream.<init>(FileOutputStream.java:58)
>  at java.io.FileOutputStream.<init>(FileOutputStream.java:128)
> 
> /home/es/java is wide open, 777. why would I be getting a permission
> denied? Here is my code:
> 
>         public static void writeToFile(String url2) {
> 
>                 String url = replacePlus(url2);
> 
>                 String outputFile = "filename.htm";
> 
>                 try {
> 
>                         File out = new File("/home/es/java",
> outputFile
> );
>                         FileOutputStream stream = new
> FileOutputStream(out);
>                         DataOutputStream writeOut = new
> DataOutputStream( stream );
>                         writeOut.writeBytes(url);
>                 }
>                 catch ( IOException ioex ) {
>                         System.out.print("Problem with file" );
>                         ioex.printStackTrace();
>                 }
> 
>         } // end of writeUrltoFile
> 
> Thanks, and BTW that other result set thing got fixed, all I did need
> was a res.next() to set the pointer to the first record. Thanks for
> the
> help.
> 
> Erick
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-devel-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-devel-help@mn-linux.org
> 
> 

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com