Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program called TextFileIO.java to create a file named numbers.dat. Then

ID: 3647681 • Letter: W

Question

Write a program called TextFileIO.java to create a file named numbers.dat. Then create an algorithm that writes all even numbered integers from 1 to 100, separated by a comma. After the file has been created, close and reopen the file and display the results to the screen. After the results have been displayed append the odd number integers from 1 to 100, separated by a comma to the end of the file. Reopen the file and display the results. The contents of the file should be the even numbers from 1 to 100 separated by a comma followed by the odd number from 1 to 100 separated by a comma. The output of this program would be something like the following

2,4,6,8,10,12,14,

Explanation / Answer

please rate - thanks

import java.io.*;
import java.util.*;
class TextFileIO
{
public static void main(String args[])throws FileNotFoundException
{int i;
FileOutputStream output;
PrintStream out=new PrintStream(new File("numbers.dat"));
for(i=2;i<100;i+=2)
   out.print(i+",");
out.print(i);
out.close();
Scanner input=new Scanner(new File("numbers.dat"));
System.out.println(input.nextLine());
input.close();
FileOutputStream out2; // declare a file output object
PrintStream p; // declare a print stream object
out2 = new FileOutputStream("numbers.dat",true);
p = new PrintStream( out2 );

for(i=1;i<100;i+=2)  
    p.print(","+i);
p.close();
Scanner in=new Scanner(new File("numbers.dat" ));
System.out.println(in.nextLine());
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote