?? hanzi.java.bak
字號:
import java.io.*;
public class HanZi{
public static void main(String args[]){
String str = "軟件工程是一門非常重要的課程!";
boolean boolObj = false;
try{
//創建一個File對象fileObj
File fileObj = new File("stuIfo.txt");
/*下面的語句首先通過使用getBytes()方法將參數字符串放到一個byte數組中,"8859_1"用于
指定編碼方式,使得輸入的漢字可以正確的輸入到文件中*/
//String wrStr = new String(str.getBytes(),"8859_1");
String wrStr = new String(str.getBytes());
/*如果當前目錄下不存在stuIfo.txt文件,就創建該文件*/
if(fileObj.exists()==false)
boolObj = fileObj.createNewFile();
/*創建一個RandomAccessFile對象,用于進行隨機訪問文件的處理*/
RandomAccessFile ranFile = new RandomAccessFile(fileObj,"rw");
//下面兩個語句將文件指針放在文件的結尾處
long len = ranFile.length();
ranFile.seek(len);
/*將字符串wrStr寫入文件的結尾處,并且每次寫入新的信息,都換行寫入*/
ranFile.writeBytes(wrStr+"\r\n");
ranFile.writeBytes("How are you"+"\r\n");
ranFile.seek(0);
String tempStr;
/*byte buf[] = new byte[50];
ranFile.readFully(buf);
tempStr = new String(buf);
System.out.println(tempStr);
*/
tempStr = ranFile.readLine();
System.out.println(tempStr);
ranFile.close();
}catch(UnsupportedEncodingException e){
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -