Results 1 to 16 of 16
- 11-12-2009, 02:18 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 15
- Rep Power
- 0
- 11-12-2009, 02:21 PM #2
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
- 11-12-2009, 02:22 PM #3
Member
- Join Date
- Oct 2008
- Posts
- 15
- Rep Power
- 0
Thanks for the reply. But is it the same when i am using a vector? :)
- 11-12-2009, 02:23 PM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 11-12-2009, 02:23 PM #5
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
- 11-12-2009, 02:25 PM #6
Member
- Join Date
- Oct 2008
- Posts
- 15
- Rep Power
- 0
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 :)
- 11-12-2009, 02:27 PM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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.
- 11-12-2009, 02:28 PM #8
Member
- Join Date
- Oct 2008
- Posts
- 15
- Rep Power
- 0
Can you give me some idea on how to edit sir.. Please? :)
- 11-12-2009, 02:28 PM #9
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
- 11-12-2009, 02:29 PM #10
Member
- Join Date
- Oct 2008
- Posts
- 15
- Rep Power
- 0
Thanks sir. wait, i have to try this task :) I want to learn.. Thanks tutorial.. i'll give an update soon :)
Regards,
Nemesis
- 11-12-2009, 02:31 PM #11
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 11-12-2009, 02:31 PM #12
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
- 11-13-2009, 01:56 AM #13
Member
- Join Date
- Oct 2008
- Posts
- 15
- Rep Power
- 0
I have this problem in storing files from the textfile to vector.
Is this okay?
This is for the main()..Java Code:public static void main(String[] args) throws FileNotFoundException { Scanner inFile = new Scanner(System.in); Vector <Subject> subj = new Vector<Subject>()
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(); }
- 11-13-2009, 07:00 AM #14
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
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).
- 11-13-2009, 08:51 AM #15
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:
- 11-13-2009, 11:00 AM #16gcampton Guest
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
-
Store textfile data in an array
By mokonji in forum New To JavaReplies: 4Last Post: 02-22-2009, 05:28 PM -
how to store the data in data base
By eclipse3.4ide in forum New To JavaReplies: 5Last Post: 02-03-2009, 04:25 AM -
How to Modify,Delete data in File Txt???
By hungleon88 in forum Advanced JavaReplies: 9Last Post: 09-24-2008, 03:19 AM -
Working with Vector objects + textfile
By SGRocker in forum New To JavaReplies: 5Last Post: 09-16-2008, 10:55 PM -
Store retrieve and delete
By on7june in forum New To JavaReplies: 1Last Post: 03-08-2008, 05:57 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks