Hi everyone....
I want to develop a music lexicon (tyoe band name --> give description) and I want to add terms (bandName and description)
I use ArrayList but I want to change. I have also the code that read a text file (bands.txt) but I dont know haw it works...
Any suggestion?

private void addTerms () 
        addTerm("Anathema","A music band from Liverpool, UK.");
import java.io.*;
   public class ReadFile
       public static void main(String[] args)
              //Sets up a file reader to read the file passed on the command line one character at a time
              FileReader input = new FileReader("bands.txt");
              //Filter FileReader through a Buffered read to read a line at a time 
              BufferedReader bufRead = new BufferedReader(input);
              String line;    // String that holds current file line
              int count = 0;  // Line number of count 
               while((line = bufRead.readLine()) != null){
                   System.out.println(count+": "+line);
                   line = bufRead.readLine();
           catch (ArrayIndexOutOfBoundsException e){
              /* If no file was passed on the command line, this expception is
              generated. A message indicating how to the class should be
              called is displayed */
              System.out.println("Usage: java ReadFile filename\n");          
          }catch (IOException e){
              // If another exception is generated, print a stack trace
6 Years
Discussion Span
Last Post by masijade

Yeah, actually learn the language (there are plenty of tutorials and API docs) rather than simply copying random blocks of code.

Why don't you tell us what you think that code is doing (line for line), see the API docs for help. At least that way you will have to actually analyse the code and learn what it does so that you are actually capable of using and modifying it, rather than just having others provide you with code that won't help you in future endeavors.


So you want to prompt your user to provide a band name and band description, then after you want to add it into your bands.txt?


Line 10, you hard-coded the file you want to read in, but in line 29, your usage requires a file name? :P

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.