Reading from txt ruins formatting
        Posted  
        
            by 
                Sorin Grecu
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Sorin Grecu
        
        
        
        Published on 2013-06-28T22:19:33Z
        Indexed on 
            2013/06/28
            22:21 UTC
        
        
        Read the original article
        Hit count: 331
        
android
I'm saving some values to a txt file and after that i want to be able to show it in a dialog.All good,done that but though the values in the txt file are formated nicely,like this :
Aaaaaaaa       0.55        1
Bbbbb          1           2.2
CCCCCCCCC      3           0.22
When reading and setting them to a textview they get all messy like this :
Aaaaaaaa      0.55         1
Bbbbb       1           2.2
CCCCCCCCC      3       0.22 
My writting method :
FileOutputStream f = new FileOutputStream(file);
        PrintWriter pw = new PrintWriter(f);
        for (int n = 0; n < allpret.size() - 1; n++) {
            if (cant[n] != Float.toString(0)
                    && pret[n] != Float.toString(0)) {
                String myFormat = "%-20s %-5s %-5s%n";
                pw.println(String.format(myFormat, prod[n], cant[n],
                        pret[n]));
My reading method :
StringBuilder text = new StringBuilder();
            try {
                BufferedReader br = new BufferedReader(new FileReader(file));
                String line;
                while ((line = br.readLine()) != null) {
                    text.append(line);
                    text.append('\n');
                }
            } catch (IOException e) {
            }
Why does it ruin the amount of spaces and how can i fix this ? Thanks and have a good night !
© Stack Overflow or respective owner