0

I am learning Java (at the age of 15) and I am currently really stuck on a part of the code. I need to know how to write to a file within an array which is in a loop but I just cant get it write. I need it so that the user enters there own answer using a scanner. I need to do it without using Output Stream.

public static void modStudents() {
    String[][] students = new String[12][4];
    String output = "";
   BufferedWriter writefile = null;

    try {
        for (int i = 0; i < 12; i++) {
             writefile = new BufferedWriter(new FileWriter("StudentNames.txt"));
            String content[] = output.split(",");
            for (int j = 0; j < 3; j++) {
                students[i][j] = content[j];
} catch (Exception e) {
        System.out.println("Somethings gone wrong");

    }
shmosel
  • 42,915
  • 5
  • 56
  • 120
  • you never open a file to read from, search "java open, read and write from file" and examples will pop up – RAZ_Muh_Taz May 31 '18 at 23:22
  • 1
    Not what you asked - but if an exception does get thrown, this code won't tell you what the problem was. Try including `e.printStackTrace();` in the `catch` block, which will give you lots of information about what caused the exception. – Dawood ibn Kareem May 31 '18 at 23:24
  • Hi, didn't mean to have that part in. It was an additional part I was doing until I got stuck on the write file part. Sorry about that. – Charlie Jones May 31 '18 at 23:24
  • Do you have a specific question? Please see [Why is “Can someone help me?” not an actual question?](http://meta.stackoverflow.com/q/284236) – shmosel May 31 '18 at 23:28

0 Answers0