public class FileWritertest {
public static void main(String[] args) {
// TODO Auto-generated method stub
FileWritertest fwt = new FileWritertest();
fwt.writerByByte("fsdfwefasdf", "d:\\test2.java");
}
public void writerByByte(String str,String filePath){
File file = new File(filePath);
FileWriter fw = null;
try {
fw = new FileWriter(file);
for(int i = 0; i < str.length(); i++)
fw.write(str.charAt(i));;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
学习笔记 - FileWriter将字符串写入文件
最新推荐文章于 2024-05-03 17:32:44 发布