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..
shotokanpoloto
0
Newbie Poster
Recommended Answers
Jump to PostHi, 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(',');
Jump to Postfollowing songokute's post, they're already in an array of strings(for every line that is)
you could use a loop to checkfor(int i =0; i < State.length ; i++) System.out.println(State[i]);
All 5 Replies
thines01
401
Postaholic
Team Colleague
Featured Poster
.:n'tQ-boy:.
0
Light Poster
shotokanpoloto
0
Newbie Poster
zeroliken
79
Nearly a Posting Virtuoso
shotokanpoloto
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.