您好,登錄后才能下訂單哦!
新增方法:
輸入:
BufferedReader breader=new BufferedReader(Reader reader);
.readLine()讀取一行內容,返回字符串
輸出:
BufferedWriter bwriter=new BufferedWirter(Writer writer);
.newLine() 寫入一個換行符
輸入:
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語言賦值表達式整個也有個真假結果
{
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();
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。