코드 ¶
원본 코드
~cpp // FileIO.java 파일 import java.io.*; import java.util.*; public class FileIO { private Formatter output; Scanner input; public String getText(String name) { String text=""; try { input = new Scanner(new File(name)); text = input.nextLine(); } catch(IOException ioException) { System.out.println("헉"); } try { output = new Formatter(name); } catch(IOException ioException) { System.out.println("헉"); } return text; } public void reverseWrite(String text) { char charArray[]=new char[text.length()]; for( int count=0; count<text.length(); count++) { charArray[count]=text.charAt(text.length()-count-1); } text=new String(charArray); output.format(text); System.out.println(text+ " 쓰기성공"); } public void fileClose() { output.close(); } } //ReverseText.java 파일 public class ReverseText { public static void main(String args[]) { String addr = "test.txt"; FileIO test = new FileIO(); test.reverseWrite(test.getText(addr)); test.fileClose(); } };