Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-12-2009, 03:18 PM
Member
 
Join Date: Oct 2008
Posts: 15
Rep Power: 0
nemesis is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-12-2009, 03:21 PM
PhHein's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Germany
Posts: 491
Rep Power: 1
PhHein is on a distinguished road
Default
Here's a tutorial with examples:
Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)
__________________
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-12-2009, 03:22 PM
Member
 
Join Date: Oct 2008
Posts: 15
Rep Power: 0
nemesis is on a distinguished road
Default
Thanks for the reply. But is it the same when i am using a vector?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-12-2009, 03:23 PM
Senior Member
 
Join Date: Aug 2009
Posts: 1,895
Rep Power: 2
r035198x is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-12-2009, 03:23 PM
PhHein's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Germany
Posts: 491
Rep Power: 1
PhHein is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 11-12-2009, 03:25 PM
Member
 
Join Date: Oct 2008
Posts: 15
Rep Power: 0
nemesis is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 11-12-2009, 03:27 PM
Senior Member
 
Join Date: Aug 2009
Posts: 1,895
Rep Power: 2
r035198x is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 11-12-2009, 03:28 PM
Member
 
Join Date: Oct 2008
Posts: 15
Rep Power: 0
nemesis is on a distinguished road
Default
Can you give me some idea on how to edit sir.. Please?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 11-12-2009, 03:28 PM
PhHein's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Germany
Posts: 491
Rep Power: 1
PhHein is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 11-12-2009, 03:29 PM
Member
 
Join Date: Oct 2008
Posts: 15
Rep Power: 0
nemesis is on a distinguished road
Default
Thanks sir. wait, i have to try this task I want to learn.. Thanks tutorial.. i'll give an update soon

Regards,
Nemesis
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 11-12-2009, 03:31 PM
Senior Member
 
Join Date: Aug 2009
Posts: 1,895
Rep Power: 2
r035198x is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 11-12-2009, 03:31 PM
PhHein's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Germany
Posts: 491
Rep Power: 1
PhHein is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 11-13-2009, 02:56 AM
Member
 
Join Date: Oct 2008
Posts: 15
Rep Power: 0
nemesis is on a distinguished road
Default
I have this problem in storing files from the textfile to vector.
Is this okay?

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?

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();
					
				}
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 11-13-2009, 08:00 AM
Senior Member
 
Join Date: Aug 2009
Posts: 1,895
Rep Power: 2
r035198x is on a distinguished road
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).
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 11-13-2009, 09:51 AM
RamyaSivakanth's Avatar
Senior Member
 
Join Date: Apr 2009
Location: Chennai
Posts: 589
Rep Power: 1
RamyaSivakanth is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 11-13-2009, 12:00 PM
gcampton's Avatar
Senior Member
 
Join Date: Oct 2009
Location: Australia, Land of the Upsidedown people
Posts: 246
Rep Power: 0
gcampton is an unknown quantity at this point
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +2. The time now is 12:33 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org