#Unexpected output in System.out.format

6 messages · Page 1 of 1 (latest)

wind meadow
#

I'm trying to debug these weird artifacts
this code ```java
public static void main(String[] args) throws FileNotFoundException {
//csv file
String CSVfileName = "PizzaInfo.csv";
System.out.println("Reading CSV file");
try {
//Open and read the file
File file = new File(CSVfileName);
Scanner input = new Scanner(file);

        System.out.println("************");
        //Retrieve the each car record display.
        while (input.hasNextLine()) {
            String line = input.nextLine();
            int length = line.length();
            String fields[] = line.split(",");
            String fieldOne = fields[0];
            String fieldTwo = fields[1];
            String fieldThree = fields[2];
            System.out.format("%-12s%-25s%-8s%n", fieldOne, fieldTwo, fieldThree);
        }
        System.out.println("****End Reading****");
        input.close();
        //Exception thrown if file name entered is incorrect.
    } catch (FileNotFoundException e) {
        System.err.println("Error: Could not open file " + CSVfileName + ". Exiting...");
    }
}```
orchid dragonBOT
#

This post has been reserved for your question.

Hey @wind meadow! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

wind meadow
#

with text in PizzaInfo.csv

2,with,12
3,no,18
4,real,14
5,meaning,3``` will output 
```****Reading CSV file****
************
1        words                    5       
2           with                     12      
3           no                       18      
4           real                     14      
5           meaning                  3       
****End Reading****```
dull flicker