Java輸入輸出

2021-08-18 11:15:53 字數 1199 閱讀 5616

從控制台讀取

1.普通讀取:scanner in = new scanner(system.in)

2.讀取密碼:console cons = system.console();

next()與

hasnext()

的區別:

string

next

()     讀取輸入的下乙個單詞,以空格作為分隔符,返回輸入的字串

boolean hasnext()      讀取下乙個單詞,以空格作為判斷符,返回檢測輸入中是否還有其他單詞

string

nextline()    讀取輸入的下一行內容,返回乙個字串

string

nextint();     boolean

hasnextint();

string

nextdouble();    boolean

hasnextdouble();

格式化輸出

system.out.printf("%8.2f",x);

string message = string.format("hello,%s i love you",name);

日期和時間的轉化符......

printf 格式符

檔案的輸入輸出

讀取:scanner in = new scanner(path.get("d:\\mydirectory\\myfile.txt"),"utf-8");

寫入:printwrite out = new printwrite("

d:/mydirectory/myfile.txt

"),"utf-8");

(上同)位址也可 "

d:\\

mydirectory

\\myfile.txt

"),"utf-8"

了解以下:

scanner(file f)

scanner(string data)

printwriter(string filename)

static path get(string pathname)

java輸入輸出

1。file 描述了檔案本身的屬性,無關流操作。iffile,isabsolute 絕對路徑否 delete,isdirectory,list 字串形式列出目錄內容 listfiles 以file物件陣列形式返回檔案列表 mkdir,mkdirs 建立目錄以及此目錄的所有父目錄 filenamefi...

java輸入輸出

一 file 類 1.構造方法 files file parent,string child 根據parent抽象路徑名和child路徑名建立新file例項 file string pathname 通過給定路徑名字字串轉換為抽象路徑名來建立乙個新file例項。file string parent,...

java輸入輸出

1。file 描述了檔案本身的屬性,無關流操作。iffile,isabsolute 絕對路徑否 delete,isdirectory,list 字串形式列出目錄內容 listfiles 以file物件陣列形式返回檔案列表 mkdir,mkdirs 建立目錄以及此目錄的所有父目錄 filenamefi...