Hey there! any question in your mind? Ask It Now!.

Popular Categories





How to write a multiple line String Array in java?

–1 vote
153 views
asked in Programming by mika (1,290 points)

Hello guys I am writing multiple lines of details for a file and using array, Somehow when i run the program it always replace the last value stored in array not all details, using this code : 

        Scanner aca = new Scanner (new File ("C:\\Users\\User\\Documents\\aca.txt"));
 
        int addAca;
 
        addAca = aca.nextInt();
        aca.close();
        FileWriter fileinp_aca = new FileWriter ("C:\\Users\\User\\Documents\\aca.txt");
        fileinp_aca.append("\n" +(addAca+1));
        fileinp_aca.close();
        PrintWriter bw_data = new PrintWriter (new FileWriter (data));
        if ((addAca-1) < ROW && (addAca -1) >= 0){
            int row = addAca - 1;
            int col = 0;
            for (int m=row; m<=50 ;) {
                for (int n = col; n<9;n++) {
                    bw_data.print (details [m][n]);
 
                details [row][col +0] = newStaff.get1();
                details [row][col +1] = newStaff.get2();
                details [row][col +2] = newStaff.get3();
                details [row][col +3] = newStaff.get4();
                details [row][col +4] = newStaff.get5();
                details [row][col +5] = newStaff.get6();
                details [row][col +6] = newStaff.get7();
                details [row][col +7] = newStaff.get8();
                details [row][col +8] = newStaff.get9();
 
 
                a = details [row][col +0];
                b = details [row][col +1];
                c = details [row][col +2];
                d = details [row][col +3];
                e = details [row][col +4];
                f = details [row][col +5];
                g = details [row][col +6];
                h = details [row][col +7];
                i = details [row][col +8];
 
                bw_data.print (a);
                bw_data.append(System.getProperty(" "));
                bw_data.print (b);
                bw_data.append(System.getProperty(" "));
                bw_data.print (c);
                bw_data.append(System.getProperty(" "));
                bw_data.print (d);
                bw_data.append(System.getProperty(" "));
                bw_data.print (e);
                bw_data.append(System.getProperty(" "));
                bw_data.print (f);
                bw_data.append(System.getProperty(" "));
                bw_data.print (g);
                bw_data.append(System.getProperty(" "));
                bw_data.print (h);
                bw_data.append(System.getProperty(" "));
                bw_data.print (i);
                bw_data.append(System.getProperty(" "));
 
                bw_data.close();
 
            break;
            }                       
                break;
            }
        }
        else
            System.out.println ("Data full.");
Can you fix it out?

Please log in or register to answer this question.

Related Questions

+3 votes
1 answer 811 views
+2 votes
1 answer 134 views
+2 votes
1 answer 177 views
0 votes
0 answers 82 views
+2 votes
2 answers 810 views
+2 votes
1 answer 860 views
+1 vote
1 answer 912 views
+6 votes
2 answers 2,966 views
0 votes
1 answer 201 views
+4 votes
5 answers 771 views

Not a Member yet?

Ask to Folks Login

My Account
438 Folks are online
3 members and 435 guest online
Your feedback is highly appreciated