怎样用FileOutputStream写一个指定类型的文件

来源:百度知道 编辑:UC知道 时间:2024/06/09 11:02:34
写个记事本
保存文件后就是没有后缀的不可读文件
怎么写成。txt文件?
我做的是仿windows记事本的
动态命名,但写成的文件类型是*.txt的
用Notepad就可以打开的

FileOutputStream fos=new FileOutputStream("C:/abc.txt");
用这一句写就可以了!写好后文件就会保存在c盘的,要注意的时你写文件保存路径时一定要把后缀名也写上.

这里有个方法直接取出后缀名的,你可以参考下:
private String getExtention(String fileName){
int type=fileName.lastIndexOf(".");
return fileName.substring(type);
}

String fileName = "d:\\hello.txt";
File file = new File(fileName);
FileOutputStream fos = new FileOutputSream(file);
然后你再试试

一样的呀,你把值取二次呀,第一次取出文件名来,第二次取出*.txt
然后你"*.txt".substring(1,"*.txt".length());取出".txt"
再把 fileName+".txt"就好了呀