Question
Do the above problem using this codes: Follow the same functions do not buffered it import java.io.*; /** * This program reads UTF-8 encoded strings
Do the above problem using this codes: Follow the same functions do not buffered it
import java.io.*;
/** * This program reads UTF-8 encoded strings from a binary file. */
public class ReadUTF { public static void main(String[] args) throws IOException { String name; boolean endOfFile = false; FileInputStream fstream = new FileInputStream("UTFnames.dat"); DataInputStream inputFile = new DataInputStream(fstream); System.out.println("Reading the names from the file:"); while (!endOfFile) { try { name = inputFile.readUTF(); System.out.print(name + " "); } catch (EOFException e) { endOfFile = true; } }
System.out.println(" Done."); inputFile.close(); } }
import java.io.*;
/** * This program opens a binary file, then reads and displays * the contents. */
public class ReadBinaryFile { public static void main(String[] args) throws IOException { int number; // To hold a number boolean endOfFile = false; // End of file flag // Open Numbers.dat as a binary file. FileInputStream fstream =new FileInputStream("Numbers.dat"); DataInputStream inputFile =new DataInputStream(fstream); System.out.println("Reading numbers from the file:"); // Read data from the file. while (!endOfFile) { try { number = inputFile.readInt(); System.out.print(number + " "); } catch (EOFException e) { endOfFile = true; } }
// Close the file. inputFile.close(); System.out.println(" Done."); } }
Develop a java app named WriteNumbersinBinaryFile.java for writing the first n natural numbers in a binary file. On the other hand, develop a java app named ReadNumbersFromBinaryFile.java for reading all integer numbers in a binary file as well as getting the sum of all numbers in the binary file. Concepts in practice: Binary Files Processing with JavaStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started