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

Java Programming- I have the following code and I have 2 places (which I have it

ID: 3770809 • Letter: J

Question

Java Programming- I have the following code and I have 2 places (which I have italicized) where I am getting a message that says: Cannot make a static reference to the non-static method (readLine() for one and close() for the other) from the type BufferedReader. I have not been able to figure out how to correct this. Nothing I have tried is working.

import java.io.*;

import java.nio.file.*;

import java.util.Scanner;

public class DisplaySavedCustomerList {

public DisplaySavedCustomerList(){

}

public static void main(String[] args){

Path path = Paths.get("C:\Users\Laptop\workspace\CustomerList.txt", new String[0]);

String args1[] = new String[4];

String s = "";

String s2 = ",";

try{

BufferedInputStream bufferedinputstream = new BufferedInputStream(Files.newInputStream(path, new OpenOption[0]));

BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(bufferedinputstream));

for(String s1 = BufferedReader.readLine(); s1 != null; s1 = BufferedReader.readLine())

{

String agrs2[] = s1.split(s2);

for(int i = 0; i < args2.length; i++)

System.out.println((new StringBuilder())

.append(args2[i]).append(" ").toString());

System.out.println();

}

BufferedReader.close();

}

catch(Exception exception) {

System.out.println((new StringBuilder()).append("Message: ").append(exception).toString());

}

}

}

Explanation / Answer

Corrected errors are Highlighted

import java.io.*;

import java.nio.file.*;

import java.util.Scanner;

public class DisplaySavedCustomerList {

   public DisplaySavedCustomerList() {

   }

   public static void main(String[] args) {

       Path path = Paths.get("C:\Users\Laptop\workspace\CustomerList.txt",

               new String[0]);

       String args1[] = new String[4];

       String s = "";

       String s2 = ",";

       try {

           BufferedInputStream bufferedinputstream = new BufferedInputStream(

                   Files.newInputStream(path, new OpenOption[0]));

           BufferedReader bufferedreader = new BufferedReader(

                   new InputStreamReader(bufferedinputstream));

//use instance of BufferedReader that you have created (i.e bufferedreader) not the class BufferedReader

           for (String s1 = bufferedreader.readLine(); s1 != null; s1 = bufferedreader

                   .readLine()) {

  //typo agrs2 change it to args2

               String args2[] = s1.split(s2);

               for (int i = 0; i < args2.length; i++)

                   System.out.println((new StringBuilder()).append(args2[i])

                           .append(" ").toString());

               System.out.println();

           }

           bufferedreader.close();

       } catch (Exception exception) {

           System.out.println((new StringBuilder()).append("Message: ")

                   .append(exception).toString());

       }

   }

}

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