We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Read Char From file .txt in java

i have a file.txt like this : 2X^2 + 5X+3=0
i want to save 2 to variable a, 5 to variable b, and 3 to variable c . .
how i can do that . . ?
tanks for your help . .

3
Contributors
3
Replies
2 Hours
Discussion Span
7 Months Ago
Last Updated
4
Views
gunvesxco
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

How do you know if a number is to go to a variable or not?
Your example skips over the second 2 and the 0?

A regular expression might help you extract the numbers from the String you posted.
Also the StreamTokenizer class could work.

NormR1
Posting Sage
Team Colleague
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16

You need two steps to do that.
1. Open text file and read content as a string http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml
2. search in the string for number you want and assagin value to the correct variable http://www.exampledepot.com/egs/java.lang/SearchString.html

kamyarn
Deleted Member

thank for your help . .

gunvesxco
Newbie Poster
3 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0634 seconds using 2.68MB