For some reason my java program can't find my textfile if i use file.next to display contents of the file but if use file.readLine it finds and shows the contencts of the filebut not the way i want for example:

I want actual output like this:

1: Humps Black Eyed Peas 3.3 Hip-Hop 4.2

But if i use next readline it displays like this:

1,Humps,Black Eyed Peas,3.3,Hip-Hop,4.2

Here is my code:

`try
            {
    BufferedReader data = new BufferedReader(new FileReader(new File("songCollection.txt")));
            Scanner inFile = new Scanner(data);
            line = data.readLine();
   System.out.printf("SongID\t " + "\tSongName\t " + "\tArtist\t " + "Duration\t " + "\tGenre\t " + "\tRating\t "  );

    while(line != null)
            {
                while(inFile.hasNext())
                {

                    //SongClass songs = new SongClass(line);
                    //songlists.add(songs);
                    //songs.setSongID(inFile.nextInt()); 

                    System.out.println(line);
                    line = data.readLine();

                }

                System.out.println(line);
                line = data.readLine();
            }

            }catch(Exception eo)
            {
                System.out.println("File Not be Found ");
            }

`

you are printing it exactly the way it is in the file. in that file, it looks like you have a comma as separator. use the split method of the String class to seperate the parts and print them the way you want.

Thats the thing when i try the split method it doesn't seem to find the fiel

that makes no sense.
you only use the split method while parsing the lines, which means after you have already read the file. the reading of the file is not impacted, unless your logic changes for some reason (which shouldn't)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.