Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I read and write a binary file?

 
Jonathan Gu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wish to read and write a binary file (.gif)
and I wonder how can i do it in Java application?
BTW, how can i read a text file "line by line"
and end by EOF?
Please give me a easy example.
Thanx a lot
A Java Beginner..
 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jonathan
You can use the following function to read a file

For reading the text file line by line you can use the following function

Hope this will help
Cheers
Amin
 
Raghavan Srinivasan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a simple example for reading from a text file line by line.
 
Jonathan Gu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx a lot..
but how can i write a byte array into a file?
Please give an example..
Thanx again
 
aminur rashid
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
To write a byte array in the file create an OutputStream and use the method
OutputStream .write(byte [] byteArray);
You can take help of following function

Cheers
 
Jonathan Gu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much..!!
if i have any achievement in Java
the credit really belongs to u guys..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic