1,105,177 Community Members

problem with file

Member Avatar
shotokanpoloto
Newbie Poster
16 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi...I want to read from a file and put each line in...the given file is like that :
q0,q1,q2;
a,b;
q0;
7;
q0,a,q0;
q0,b,q1;
.
.
.
.
(as you see it's the information of a nfa)
Each line ends with ";" and each element of array is separated with ","...for example
for line 1 we should define an array for example "States" and the array is like that :
State[1]=q0
State[2]=q1
State[3]=q2
can anyone help me with it ? I don't know how to do that...I searched Tokenizer method,
but still have problem with details of my file as I explained for you..

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
0
 
Member Avatar
.:n'tQ-boy:.
Light Poster
30 posts since Dec 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
1
 

Hi, i think you can use Scanner to read from file. Scanner has a method 'readLine()' that reads line by line.
Each time you read a line, assume that you assign that value to a variable named 'strtmp', then you use 'split()' method.
Eg:
strtmp = scan.readLine();
State = strtmp.split(',');

Try this, i think it will help!

Member Avatar
shotokanpoloto
Newbie Poster
16 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, i think you can use Scanner to read from file. Scanner has a method 'readLine()' that reads line by line.
Each time you read a line, assume that you assign that value to a variable named 'strtmp', then you use 'split()' method.
Eg:
strtmp = scan.readLine();
State = strtmp.split(',');

Try this, i think it will help!

thanks.Now I want to know how to put each item in array
for example:
q0,q1,q2;
State[0]=q0
State[1]=q1
State[2]=q2

Member Avatar
zeroliken
Nearly a Posting Virtuoso
1,222 posts since Nov 2011
Reputation Points: 79 [?]
Q&As Helped to Solve: 216 [?]
Skill Endorsements: 15 [?]
 
1
 

following songokute's post, they're already in an array of strings(for every line that is)
you could use a loop to check

for(int i =0; i < State.length ; i++)
    System.out.println(State[i]);
Question Answered as of 2 Years Ago by thines01, zeroliken and .:n'tQ-boy:.
Member Avatar
shotokanpoloto
Newbie Poster
16 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

thanks alot!it was useful.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: