java中如何把一段字串寫入檔案中

時間 2021-06-25 14:54:06

1樓:ppos丨丶灬瘋傑

string str="i love china!"

file txt=new file("c:\documents and settings\administrator\桌面\nihao.txt");

if(!txt.exists())

byte bytes=new byte[512];

bytes=str.getbytes(); //新加的int b=str.length(); //改fileoutputstream fos=new fileoutputstream(txt);

fos.write(bytes,0,b);

fos.close();

如何判斷字串中存在另外字串java

肖颯盤靈韻 1 public intindexof int ch string str 用於查詢當前字串中字元或子串,返回字元或子串在當前字串中從左邊起首次出現的位置,若沒有出現則返回 1。2 public intindexof int ch string str,intfromindex 該方法與...

sql中如何統計段中字串的個數

看你用什麼樣的資料庫去實現,sql server oracle 所使用的函式語句有出入的。查查具體資料庫的函式 語句。做個儲存過程應該就能搞定 用replace 將空格替換成 就是空的,然後跟原先的字元長度比較,得出的就是字串的個數。嘿嘿 剛剛想到的。select id,len nr len rep...

java中如何擷取字串中的指定一部分

具體方法如下 string usename f workspace ssh photo webcontent uploadfile 1444783552338pic.jpg int begin usename.indexof int last usename.length system.out.pr...