U E D R , A S I H C RSS

토이/메일주소셀렉터/김정현

= 소스 =
파일로부터 입력을 받아 가공하여 다시 파일에 저장



//메인클래스
public class Main {

	public static void main(String[] args) {
		String input;
		if(args.length==0) 
			input= "input.txt";
		else input = args[0];
		
		FileIo io= new FileIo();
		String[] deleteList= {" ", "\n"};
		io.insertDeleteList(deleteList);
		io.insertSpace(true);
		io.write("result.txt", io.getRemadeFromFile(input));
	}
}



// 파일처리 클래스
import java.io.*;

public class FileIo {

	private String[] deleteList= {};
	private boolean shouldInsertSpace;
	public FileIo() {
		shouldInsertSpace= false;
	}

	public void write(String fileName, String text) {
		FileWriter fw;
		try {
			fw = new FileWriter(getTextFileForm(fileName));
			BufferedWriter bw = new BufferedWriter(fw);			
			bw.write(text);	
			bw.close();
			fw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String read(String fileName) {
		FileReader fr;
		String resultString= "";	
		
		try {
			fr = new FileReader(getTextFileForm(fileName));
			BufferedReader br = new BufferedReader(fr);
			while(br.ready()) {
				resultString += br.readLine();			
			}
			br.close();
			fr.close();
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return resultString;
	}

	public String getTextFileForm(String inputName) {
		String tempString= inputName.replace('.', '-');
		String[] splitedStrings= tempString.split("-");
		if(splitedStrings.length == 2 && splitedStrings[1].equals("txt")) {
			return inputName;
		}
		return inputName + ".txt";
	}

	public void insertDeleteList(String[] deleteList) {
		this.deleteList= deleteList;
	}

	public String getRemade(String input) {
		String temp= input;
		for (String string : deleteList) {
			temp= temp.replace(string, "");
		}
	
		if(shouldInsertSpace) {
			char[] chars= temp.toCharArray();
			temp= "";
			for (char c : chars) {
				temp= temp + c + " ";
			}
		}
		
		return temp;
	}

	public void insertSpace(boolean shouldInsertSpace) {
		this.shouldInsertSpace= shouldInsertSpace;
	}

	public String getRemadeFromFile(String fileName) {
		return getRemade(read(fileName));
	}

}


----

토이/메일주소셀렉터
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:21
Processing time 0.0108 sec