您好,登錄后才能下訂單哦!
新增方法:
輸入:
BufferedReader breader=new BufferedReader(Reader reader);
.readLine()讀取一行內(nèi)容,返回字符串
輸出:
BufferedWriter bwriter=new BufferedWirter(Writer writer);
.newLine() 寫入一個(gè)換行符
輸入:
File f =new File("C:\Users\10853\eclipse-workspace\hell\src\hell\abc");
BufferedReader reader=null;
try {
reader=new BufferedReader(new FileReader(f));
String line=null;
while((line=reader.readLine())!=null)//要添上!=null,不像c語(yǔ)言賦值表達(dá)式整個(gè)也有個(gè)真假結(jié)果
{
System.out.println(line);
}
}catch(FileNotFoundException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}finally {
try {
if(null!=reader)
{
reader.close();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
輸出:
File f=new File("D:d/c.txt");
BufferedWriter bwriter=null;
try
{
bwriter=new BufferedWriter(new FileWriter(f));
String s="addad";
bwriter.write(s);
bwriter.newLine();
bwriter.append("aaaff");
bwriter.flush();
}catch(FileNotFoundException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}finally {
try {
if(null!=bwriter)
{
bwriter.close();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。