私は次のようなテキストファイルからすべての行の最初の単語を読まなければならない大学のプロジェクトを持っています:
23123123213 Samuel classA
23423423423 Gina classC
23423423423 John classD
テキストファイルは3つの JTextField
で更新されます。
今はすべての行の最初の単語(23123123213,23423423423および23423423423)で JCombobox
を設定する必要があります。
私はJavaに新しいです、私はそれを行う方法のヒントを持っていない。
私はテキストファイルを読み書きする方法を知っています。
誰かが私にこれを手伝ってもらえますか?
これまでのコードは次の通りです:
import java.io.*;
public class FileRead
{
public static void main(String args[])
{
try{
//Open the file that is the first
//command line parameter
FileInputStream fstream = new FileInputStream("RokFile.txt");
//Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
String[] delims = strLine.split(" ");
String first = delims[0];
System.out.println("First word: "+first);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
あなたの助けを借りて、私は各行から最初の文字列を抽出することに成功しました
しかし、今私はJcomboboxでそれを設定することができます、私はどこか最初にそれを保存する必要がありますか?
前もって感謝します