Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: I need help with removing arrays or hiding them.

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default I need help with removing arrays or hiding them.

    Ok I have a text file that looks like this:

    Yellow Submarine
    Beatles
    Rock
    Welcome to my life
    Simple plan
    Alternative
    Break
    Three Days Grace
    Rock

    There are 9 files and 3 arrays. One for songs, one for artists and one for genre.
    I want to delete or remove from the array the song "Welcome to my life"

    I want to delete it by pushing it out to the end of the array, then overwriting it so it doesn't show.


    My for loops are wrong. Can you help me with my code? Il really appreciate it.



    static void Delete (String[] Song, String[] Artist, String[] Category, int[] count, String[] database) throws IOException //Delete a song from the collection
    {
    BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in));
    BufferedReader reader = new BufferedReader (new FileReader (database [0] + ".txt"));
    BufferedWriter writer = new BufferedWriter (new FileWriter (database [0] + ".txt", true));
     
    String deletechoice; //asks user what to delete
    String temp; // temp files
     
    // reads file
     
    String line1 = null;
     
    while ((line1 = reader.readLine ()) != null)
    {
    Song [count [0]] = (line1);
    line1 = reader.readLine ();
    Artist [count [0]] = (line1);
    line1 = reader.readLine ();
    Category [count [0]] = (line1);
    }
    reader.close ();
     
    // asks user to locate song
     
    System.out.println ();
    System.out.println ("What song would you like to delete?: ");
    deletechoice = (stdin.readLine ());
     
    for (int k = 0 ; k < count [0] ; k++) //searches efficently for the file
    {
    boolean Found = false;
     
    if (deletechoice.equalsIgnoreCase (Song [k]))
    {
    System.out.println ("It exists, so it will be deleted " + k);
    Found = true;
     
     
    for (int i = count [0] ; i < count [0] - k ; i++)
    {
    temp = Song [i];
    Song [i] = Song [i - 1];
    Song [i - 1] = temp;
     
    temp = Artist [i];
    Artist [i] = Artist [i - 1];
    Artist [i - 1] = temp;
     
    temp = Category [i];
    Category [i] = Category [i - 1];
    Category [i - 1] = temp;
    }
     
    //overwrites it 
     
    for (int j = 0 ; j < count [0] - k ; j++)
    {
    writer.write (Song [j]);
    writer.newLine ();
    writer.write (Artist [j]);
    writer.newLine ();
    writer.write (Category [j]);
    writer.newLine ();
    }
    writer.close ();
    }
    else if (!(deletechoice.equals (Song [k])))
    {
    System.out.print ("----searching------");
    }
    }
     
    }


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: I need help with removing arrays or hiding them.

    This thread has been cross posted here:

    http://www.javaprogrammingforums.com/whats-wrong-my-code/15293-im-having-problems-removing-arrays.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting
    This thread has been cross posted here:

    http://www.javaprogrammingforums.com/whats-wrong-my-code/15294-i-am-most-terrible-file-reader.html#post64368

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting

    You didn't done anything wrong, though I'd highly recommend not opening a fourth thread for this same topic. (The mods really won't like it. They might delete some of them. )

    Also, instead of deleting that song, what is it doing?

    Are there any Exceptions being thrown or is it simply doing nothing?

    Last edited by javapenguin; April 22nd, 2012 at 08:45 PM.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I need help with removing arrays or hiding them.

    Honestly the for loops are wrong and nothing is happening....

  4. #4
    Junior Member
    Join Date
    Mar 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help with removing arrays or hiding them.

    Why do you have an array that stores 1 number?

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I need help with removing arrays or hiding them.

    I need to delete only that array and shift the artists and genres that correlate with that song.

    I honestly don't know what you mean. It a string array.

Similar Threads

  1. [SOLVED] I'm having problems with removing arrays
    By seaofFire in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 23rd, 2012, 11:18 AM
  2. Java Not Removing Panels?
    By Pantheon8 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 17th, 2011, 07:54 PM
  3. Hiding\Showing parts of the frame
    By liron50 in forum AWT / Java Swing
    Replies: 17
    Last Post: April 29th, 2011, 12:14 PM
  4. Data hiding and maintainability
    By humdinger in forum Object Oriented Programming
    Replies: 11
    Last Post: December 5th, 2009, 01:10 PM
  5. Arrays: question about "removing" items.
    By sanfor in forum Collections and Generics
    Replies: 2
    Last Post: November 30th, 2009, 04:09 AM