Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Stringtokenizer - read String from *.txt files - How to read next Lines???

807601May 6 2008 — edited May 9 2008
// **** i wrote down a lot but i couldnt get how to read other lines??





import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;

public class readerF
{
public static String[] verioku(String nameF) throws IOException
{
BufferedReader fin=new BufferedReader(new FileReader(nameF));
String s1=fin.readLine();
StringTokenizer token=new StringTokenizer(s1);
int n=token.countTokens()-1;
int m=n+1;

String s[]=new String[m];
int i=0;

while (token.hasMoreTokens()) {

s=token.nextToken();
i++;
}


return s;
}
public static void main(String args[]) throws IOException
{
String namef=JOptionPane.showInputDialog("file name:(b.txt)");
String numberf[]=readerF(namef);
String s="";
for(int i=0;i<numberf.length;i++)
{s+="number["+i+"] = "+numberf[i]+"\n";}
JOptionPane.showMessageDialog(null,s,"read from text",JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 6 2008
Added on May 6 2008
23 comments
4,287 views