1つの.txtファイルから2行を取り出してダイアログボックスに出力する必要があります。現在のコードは特定の行を読む - Java
private String getfirstItem() {
String info = "";
File details = new File(myFile);
if(!details.exists()){
try {
details.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
BufferedReader read = null;
try {
read = new BufferedReader (new FileReader(myFile));
} catch (FileNotFoundException e3) {
e3.printStackTrace();
}
for (int i = baseStartLine; i < baseStartLine + 1; i++) {
try {
info = read.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
firstItem = info;
try {
read.close();
} catch (IOException e3) {
e3.printStackTrace();
}
return firstItem;
}
private String getsecondItem() {
File details = new File(myFile);
String info = "";
BufferedReader reader = null;
if(!details.exists()){
try {
details.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}}
try {
reader = new BufferedReader (new FileReader(myFile));
} catch (FileNotFoundException e3) {
e3.printStackTrace();
}
for (int i = modelStartLine; i < modelStartLine + 1; i++) {
try {
info= reader.readLine();
} catch (IOException e) {
e.printStackTrace();}
modelName = info;} try {
reader.close();
} catch (IOException e3) {
e3.printStackTrace();
}
return secondItem;
}
ですが、どちらも同じ値が得られますか? modelStartLine = 1とbaseStartLine = 2
ありがとうございます! – RayCharles