Question : Reading a txt file line by line

Hi I have got the floowing txt

Nenu Neeku/Achu
Aerosmith Amazing/Aerosmith
college Dropout/Kanye West

I am trying to read only the name before '/' . I am getting the output but i am having lot of comments added before, just like the following.

[{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540, {\fonttbl\f0\fswiss\fcharset0 Helvetica;}, {\colortbl;\red255\green255\blue255;}, \margl1440\margr1440\vieww9000\viewh8400\viewkind0, \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural, , \f0\fs24 \cf0 Nenu Neeku, Aerosmith Amazing, college Dropout]


attached the complete code


Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
package kalyangkm;
 
import java.util.*;
import java.io.*;
 
public class Playlist {
	
	ArrayList songList = new ArrayList ();
	
	public static void main(String[] args){
		new Playlist().go();
		
	}
	
	public void go() {
		getSongs();
		System.out.println(songList);
	}
	
	               		
	public void getSongs() {
        try {
            File file = new File(System.getProperty   ("user.home"),"SongList.rtf");
            Scanner in = new Scanner(file);
            while (in.hasNextLine()) {
                addSong(in.nextLine());
            }
            in.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }                           
	
	
	public void addSong(String lineToParse){
		String[] tokens = lineToParse.split("/");
		songList.add(tokens[0]);
	}
}

Answer : Reading a txt file line by line

In TextEdit, go to the "Format" menu.  Then choose "Make Plain Text".
Now, go to save (or Save As) and save your document.

 Now, you'll have a Plain Text document.
next in your file input

Change the following line
File file = new File(System.getProperty   ("user.home"),"SongList.rtf");

to

File file = new File(System.getProperty   ("user.home"),"SongList.txt");

Or by whatever name you have saved the file as

Random Solutions  
 
programming4us programming4us