Home>

First, check the file address of the executable program.
Scan "Member.txt" file at the same address line by line and assign to String PLAYER_NAMES [] = new String [15]. I want to do that.

Error message

To see if it is done, use for minutes and check with System.out.println (PLAYER_NAMES [i])

null
null
null
...
null


It will become.

Applicable source code
public static void main (String args []) {
System.out.println ("Member input processing");
        try {
            String File_Address = get_currentpath ();
            File file = new File (File_Address + "Member.txt");
            Scanner scan2 = new Scanner (file);
            scan2.useDelimiter ("\ r \ n");
            int line = 1;
            System.out.println (line);
            while (scan2.hasNext ()) {
                System.out.println (line);
                String str = scan2.next ();
                PLAYER_NAMES [line] = str;
                line ++;
                System.out.println (PLAYER_NAMES [line]);
            }
        } catch (FileNotFoundException e) {
            System.out.println (e);
        }
}
private static String get_currentpath () {
        String cp = System.getProperty ("java.class.path");
        String fs = System.getProperty ("file.separator");
        String acp = (new File (cp)). GetAbsolutePath ();
        int p, q;
        for (p = 0;(q = acp.indexOf (fs, p))>= 0;p = q + 1);
        return acp.substring (0, p);
    }
}
  • Answer # 1

    PLAYER_NAMES [line] = str;
    line ++;
    System.out.println (PLAYER_NAMES [line]);
    It would be bad if the

    line increment was first.

    PLAYER_NAMES [line] = str;
    System.out.println (PLAYER_NAMES [line]);
    line ++;

Trends