package exceltest;
import java.io.FileWriter;
import java.io.IOException;
public class WriterTest {
public static void main(String[] args) {
String filepath = "C:\\Users\\ybb\\Desktop\\test2.txt";
FileWriter fileWriter = null;
try {
fileWriter = new FileWriter(filepath);
fileWriter.write("小王上课");
fileWriter.write('H');
fileWriter.write("小李去买东西", 0, 2);
char[] chars = {'H', 'C', 'U'};
fileWriter.write(chars, 0, 2);
fileWriter.write(chars);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
输出结果:
小王上课H小李HCHCU