Question

7. Write a program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binar

  1. Write a program that reads the integer numbers in a text file (numbers.txt) and stores the numbers to a binary file (binaryNumber.dat). (5 pts)

The number.txt file contains the following numbers:

1 2 3 4 5 6 7 8 9 0

0 0
Add a comment Improve this question Transcribed image text
Answer #1

java code:

  
import java.io.*;

public class ConvertToBin {

public static void main(String[] args) {

String inFile ="numbers.txt";
String ouFile ="binaryNumber.dat";


try (
InputStream inputStream = new FileInputStream(inFile);
OutputStream outputStream = new FileOutputStream(ouFile);
) {

long fileSize = new File(inFile).length();

byte[] Bytes = new byte[(int) fileSize];

inputStream.read(Bytes);

outputStream.write(Bytes);

} catch (IOException ex) {
ex.printStackTrace();
}
}
}

Add a comment
Know the answer?
Add Answer to:
Write a program that reads the integer numbers in a text file (numbers.txt) and stores the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT