U E D R , A S I H C RSS

문자반대출력/김정현

소감

자바에서 파일입출력은 아직도 잘 모르겠다


코드

원본 코드
~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();
	}
};



나한테 할말

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:30
Processing time 0.0082 sec