java 更新文件内容吗_java Io流更新文件内容
標(biāo)簽:
package com.hp.io;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutputStreamTest{
public static void main(String []args){
FileOutputStream fos=null;??? //文件輸出流
try{
String str="java從入門到放棄";
byte [] words =str.getBytes();?? //創(chuàng)建一個中轉(zhuǎn)存放字節(jié)
fos =new FileOutputStream("f:\\入門.txt");? //可以選擇已有的也可以隨便寫一個 會自動創(chuàng)建一個文件
fos.write(words,0,words.length);? // 開始寫入? words中的數(shù)據(jù)? 數(shù)據(jù)大小從0到words的長度,注意這里不是求最大值 不是words.length-1
System.out.println("文件已更新");
}catch(IOException e){
System.out.print("創(chuàng)建文件時出錯");
}finally{
try{
if(fos!=null)
fos.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
標(biāo)簽:
總結(jié)
以上是生活随笔為你收集整理的java 更新文件内容吗_java Io流更新文件内容的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java ear war_[JAVA语法
- 下一篇: centos运行java图形化界面_Ce