Results 1 to 16 of 16
  1. #1
    nemesis is offline Member
    Join Date
    Oct 2008
    Posts
    15
    Rep Power
    0

    Default How to store data from textfile to vector and delete a selected row.

    Can someone teach me how to store data from textfile to vector and delete a selected row. And after deleting, i want to write the changes in my textfile.

    Do someone has an idea? :)

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    nemesis is offline Member
    Join Date
    Oct 2008
    Posts
    15
    Rep Power
    0

    Default

    Thanks for the reply. But is it the same when i am using a vector? :)

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Character Streams (The Java™ Tutorials > Essential Classes > Basic I/O)

    Read that page especially the Line Oriented section, make an attempt and post if you get problems with your code.

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Do you have to use a Vector? Vector is a bit deprecated. You can use any kind of List.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  6. #6
    nemesis is offline Member
    Join Date
    Oct 2008
    Posts
    15
    Rep Power
    0

    Default

    Sorry sir, my teacher says we should use vectors.. I am able to add and delete files from the textfile.. But i have a big problem regarding for editing and deleting a file in my textfile.

    Thanks for the time :)

  7. #7
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    You mean you are able to add and delete lines?
    Well to edit, just edit the value inside the Vector itself and then rewrite the file again the same you rewrote it after deleting lines.

  8. #8
    nemesis is offline Member
    Join Date
    Oct 2008
    Posts
    15
    Rep Power
    0

    Default

    Can you give me some idea on how to edit sir.. Please? :)

  9. #9
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Basically do this:
    1) read file and store every line as a String in your Vector
    2) modify or delete lines as you need in the Vector
    3) write every line from the Vector back into the file.

    1) and 3) are covered in the tutorial
    2) is your job as we cannot tell you what to change.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  10. #10
    nemesis is offline Member
    Join Date
    Oct 2008
    Posts
    15
    Rep Power
    0

    Default

    Thanks sir. wait, i have to try this task :) I want to learn.. Thanks tutorial.. i'll give an update soon :)

    Regards,
    Nemesis

  11. #11
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by nemesis View Post
    Can you give me some idea on how to edit sir.. Please? :)
    The first step is to find the one that you want to delete from the vector.
    There are several methods already in the Vector class for doing this. Then you simply replace that element with the new one.

  12. #12
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    And never ever crosspost again with out linking the threads!
    Java Programming - How to store data from textfile to vector and delete a selected row.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  13. #13
    nemesis is offline Member
    Join Date
    Oct 2008
    Posts
    15
    Rep Power
    0

    Default

    I have this problem in storing files from the textfile to vector.
    Is this okay?

    Java Code:
    public static void main(String[] args) throws FileNotFoundException
    	{
    		Scanner inFile = new Scanner(System.in);
    		Vector <Subject> subj = new Vector<Subject>()
    This is for the main()..

    Can someone check this code for me? :)

    Java Code:
    while(scanner.hasNextLine())
    					{
    						String lineremove = scanner.nextLine();
    						z++;
    						System.out.println(z + " " + lineremove);
    					}
    	
    				System.out.println("What do you want to remove?");
    				System.out.println();
    				selectRemove = inFile.nextInt();
    				
    				
    				Subject v = new Subject();
    				while (scanner.hasNext())
    				{
    					String lineforremove = scanner.nextLine();
    					v.add(lineforremove);
    				}
    				
    				System.out.println(subj.size());
    				try
    				{
    				
    					boolean append = true;
    					pw = new PrintWriter(new FileWriter(new File("subjects.txt"), append));
    					pw.println(subj.toString());
    				}
    					catch (IOException e)
    					{
    						e.printStackTrace();
    					}
    				finally
    				{
    				
    					pw.close();
    					
    				}

  14. #14
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Write at least three separate methods.

    1.) Reads the file lines into a Vector.
    2.) Writes the lines in the vector to a file.
    3.) Edits an entry in the vector (has nothing to do with files).

  15. #15
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Before started writing,just try to put comments before the methodd that what logic u are going to perform.How the data is formatted in ur text file like that...Then only it will be simpler for the people to give suggestions.
    Ramya:cool:

  16. #16
    gcampton Guest

    Default

    Also as a standard, you teacher should be teaching you to write variables with camel case.(each word start uppercase except the first) lineforremove should be lineForRemove as an example as this is easier to read.

    He/she should also probably not be teaching you to use depreciated classes either, sounds like he needs to brush up on his/her java skills.

Similar Threads

  1. Store textfile data in an array
    By mokonji in forum New To Java
    Replies: 4
    Last Post: 02-22-2009, 06:28 PM
  2. how to store the data in data base
    By eclipse3.4ide in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 05:25 AM
  3. How to Modify,Delete data in File Txt???
    By hungleon88 in forum Advanced Java
    Replies: 9
    Last Post: 09-24-2008, 04:19 AM
  4. Working with Vector objects + textfile
    By SGRocker in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 11:55 PM
  5. Store retrieve and delete
    By on7june in forum New To Java
    Replies: 1
    Last Post: 03-08-2008, 06:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •