본문 바로가기

Java

line copy

public static void lineCopy() {
	String rootPath = ".";
	String outFolder = "/output";
	String fileName = "Client.java";

	File oFolder = new File(rootPath+outFolder);
	if (!oFolder.exists())
		oFolder.mkdirs();

	File inFile = new File(rootPath, fileName);
	File outFile = new File(rootPath+outFolder, fileName);
	BufferedReader in = null;
	BufferedWriter out = null;

	try {
		in = new BufferedReader(new FileReader(inFile));
		out = new BufferedWriter(new FileWriter(outFile, false));
		String line;
		while ((line = in.readLine()) != null) {
			out.write(line);
			out.newLine();
		}
		out.flush();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			if (in != null) in.close();
			if (out != null) out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}