Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes File Read  & Writing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "File Read  & Writing" Watch "File Read  & Writing" New topic
Author

File Read & Writing

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
file = "test.txt";
I have to use PrintWriter to print out my info, but it once a char not a byte. How can I convert my data to a char or read it as a char.
Right now, this does not compile cause
out.write(buf, 0, bytesRead) once a char not a byte.
Please Help
######################
File file1 = new File(file);
FileInputStream fis = null;
fis = new FileInputStream(file1);
PrintWriter out = new PrintWriter(res.getWriter());
byte[] buf = new byte[4 * 1024]; // ???
int bytesRead;
while ((bytesRead = in.read(buf)) != -1)
{
out.write(buf, 0, bytesRead);
}
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
HI,
create a BufferedReader and pass in the FileInputStream like this
BufferedReader buff = new BufferedReader( fis ) ;
The BufferedReader.read() method reads in data from the InputStream and converts it to a char. It also has a readLine() methos and skip(long chars) which can be handy.
Hope that helps,

------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform


Raising Flares debut album 'Ignition' out now

http://www.raisingflares.com

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: File Read & Writing
 
Similar Threads
FTP Upload
Copying Multiple Files Over A Socket
Display Image in JSP using servlet
Directory Download Servlet(Need your help asap!)
Read file X lines