package javaapplication1;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class JavaApplication1 {
public static void main(String[] args) throws IOException {
String s = "java c";
BufferedWriter bw = null;
FileWriter fw = null;
try {
File file = new File("d:\\data.txt");
if (!file.exists()) {
file.createNewFile();
}
fw = new FileWriter(file.getAbsoluteFile(), true);
bw = new BufferedWriter(fw);
bw.newLine();
bw.write(s.charAt(5));
} catch (IOException e) {
System.out.println(e);
} finally {
try {
if (bw != null) {
bw.close();
}
if (fw != null) {
fw.close();
}
} catch (IOException e) {
System.out.println(e);
}
}
}
}
/* file: data.txt
text line 1
c
*/
/*
run:
*/