| | |
Write File to disk
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 126
Reputation:
Solved Threads: 6
Hi all,
I am trying to create a file and write something into that file.
Here's what I have tried:
But, when I run this program, no file is created. Can someone help me out with that. Where I went wrong.
Thanks.
I am trying to create a file and write something into that file.
Here's what I have tried:
Java Syntax (Toggle Plain Text)
import java.io.*; import java.util.*; public static void main (String[] arg) { try { String file_name = "test.txt"; FileWriter file = new FileWriter(file_name); BufferedWriter out = new BufferedWriter (file); String text = "This is goint to be written to the file"; out.write(text); out.close(); } catch (IOException e) { System.out.println(e.getMessage()); } }
But, when I run this program, no file is created. Can someone help me out with that. Where I went wrong.
Thanks.
I do not know how you can run this file when in the state as is it would not compile with about 10 error messages. What about class declaration
Difficult to comment on realy beginners stuff which you should know
public class CreateTestTxt for example Java Syntax (Toggle Plain Text)
import java.io.*; import java.util.*; public class CreateTestTxt { public static void main (String[] arg) { try { String file_name = "test.txt"; FileWriter file = new FileWriter(file_name); BufferedWriter out = new BufferedWriter (file); String text = "This is goint to be written to the file"; out.write(text); out.close(); } catch (IOException e) { System.out.println(e.getMessage()); } } }
Difficult to comment on realy beginners stuff which you should know
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Apr 2007
Posts: 126
Reputation:
Solved Threads: 6
•
•
•
•
I do not know how you can run this file when in the state as is it would not compile with about 10 error messages. What about class declaration
Java Syntax (Toggle Plain Text)
public class CreateTestTxt
But question, was that even with class declaration, like the one that you replied back, I wasn't able to make this simple code work.
I created another file, with different name. I compiled it, and ran it, it worked fine.
•
•
•
•
Difficult to comment on realy beginners stuff which you should know
But I should tell you, good observation.
Last edited by new_2_java; Apr 22nd, 2007 at 1:24 pm.
![]() |
Similar Threads
- wirte a file with startup disk (IT Professionals' Lounge)
- Write to a file in C++ (C++)
- Read/write to same file > once, Help (C++)
- write in file and screen? (C++)
- Write to a file (C)
- line up JTextField GUI java & write to file (Java)
Other Threads in the Java Forum
- Previous Thread: java text field for password please
- Next Thread: Help me how to find a host ip in Network using java program
Views: 9066 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






