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