파일의 줄을 변경하는 데 문제가 있습니다.이 코드의 목적은 파일의 첫 번째 번호를 자신이 +1로 변경하는 것입니다. 어떤 이유로 코드에서 ' 전혀 작동하지 않는 것 같아요, 어떤 도움을 주시면 감사하겠습니다!파일의 첫 번째 줄 변경
public static void changenumber(String fileName)
{
ArrayList<String> list = new ArrayList<String>();
File temp = new File(fileName);
Scanner sc;
try {
sc = new Scanner(temp);
while (sc.hasNextLine())
{
list.add(sc.nextLine());
}
sc.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
String first = list.get(0);
int i = Integer.parseInt(first);
i = i+1;
first = Integer.toString(i);
list.set(0, first);
writenumber(list,fileName);
}
public static void writenumber(ArrayList<String> list, String fileName)
{
PrintWriter write;
try {
write = new PrintWriter(new FileWriter(fileName, true));
for(int i = 0; i<list.size();i++)
{
write.append(list.get(i));
}
}
catch(IOException err)
{
err.printStackTrace();
}
}
PrintWriter를 플러시 할 수 있습니까? – jrtapsell