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

For Java Programing, 1. Name at least five different file categories. 2. What ki

ID: 3805874 • Letter: F

Question

For Java Programing,

1. Name at least five different file categories.

2. What kind of data may be stored in a file?

3. What are at least four methods associated with file processing (using JAVA of course)?

4) Execute the following code to read a file.

import java.io.*;

public class ReadFile {

public static BufferedReader buffer;

       public static void main(String[] args)

       {

              try {

              // create a FileReader object

                     FileReader file = new FileReader("Frost.txt");

              // create a BufferedReader object to read the file    

                     BufferedReader buffer = new BufferedReader(file);

                     String line ="";

                           while((line=buffer.readLine()) !=null)

                           {

                                  System.out.println(line);

                                  }   

              //close the BufferedReader Object

        buffer.close();

       }

              catch (IOException e)

              {

                     System.out.println("A read error has occurred");

              }

             

       }

       }

Explanation / Answer

1. Name at least five different file categories.

Answer: .txt, .dat, .xml, .dox, .xls, .ppt,

2. What kind of data may be stored in a file?

Answer: text based data stored in a file.

Frost.txt

aaaa

bbbb

cccc

dddd

eeee

3. What are at least four methods associated with file processing (using JAVA of course)?

Answer:

readLine() method is used to read a line from a file

close() method is used to close the file

read() method is used to read a single character

mark() method is used to marh the present position in Stream

skip() method is used to skip the chracters

4) Execute the following code to read a file.

Answer:

ReadFile.java

package a4;

import java.io.*;
public class ReadFile {
public static BufferedReader buffer;
public static void main(String[] args)
{
try {
// create a FileReader object
FileReader file = new FileReader("Frost.txt");
// create a BufferedReader object to read the file
BufferedReader buffer = new BufferedReader(file);
String line ="";

while((line=buffer.readLine()) !=null)
{
System.out.println(line);
}   
//close the BufferedReader Object
buffer.close();
}
catch (IOException e)
{
System.out.println("A read error has occurred");
}

}
}

Output:

aaaa

bbbb

cccc

dddd

eeee

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