Results 1 to 3 of 3
Thread: help me to store data in a class
- 02-26-2009, 01:17 PM #1
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
- 02-26-2009, 02:41 PM #2
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
You use the FileWriter and BufferedWriter class:
Class FileWriter
The FileWriter is a class used for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.
BufferedWriter
The BufferWriter class is used to write text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.
Example
Java Code:import java.io.*; class FileWrite { public static void main(String args[]) { FileWriter fstream = new FileWriter("name.txt"); //create a file called name.txt BufferedWriter out = new BufferedWriter(fstream); // create a writing stream out.write("Hello Java"); //write whatever you want out.close(); // stops writing } }Last edited by georgexu316; 02-26-2009 at 02:44 PM.
- 08-06-2009, 08:31 AM #3
Member
- Join Date
- Jul 2009
- Posts
- 2
- Rep Power
- 0
--------------------Configuration: <Default>--------------------
C:\FileWrite.java:7: unreported exception java.io.IOException; must be caught or declared to be thrown
FileWriter fstream = new FileWriter("name.txt"); //create a file called name.txt
^
C:\FileWrite.java:9: unreported exception java.io.IOException; must be caught or declared to be thrown
out.write("Hello Java"); //write whatever you want
^
C:\FileWrite.java:10: unreported exception java.io.IOException; must be caught or declared to be thrown
out.close(); // stops writing
^
3 errors
Process completed.
hehe i've just got this when I copy paste your code
ohh I forgot to right the throws IOException beside public static void main (String []args) __(>throws IOException<)__Last edited by chrisjake; 08-06-2009 at 08:33 AM. Reason: i forgot to write this sorry...
Similar Threads
-
Store textfile data in an array
By mokonji in forum New To JavaReplies: 4Last Post: 02-22-2009, 05:28 PM -
how to store the data in data base
By eclipse3.4ide in forum New To JavaReplies: 5Last Post: 02-03-2009, 04:25 AM -
How to read data from excel and store it in db
By saran123 in forum New To JavaReplies: 5Last Post: 10-03-2008, 10:19 AM -
How to create folder(s) and store data?
By Grom in forum New To JavaReplies: 2Last Post: 08-20-2008, 09:01 AM -
how to use btree to store data
By fred in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks