關(guān)于java基礎(chǔ)筆試代碼題,java代碼練習(xí)題這個(gè)問(wèn)題很多朋友還不知道,今天小六來(lái)為大家解答以上的問(wèn)題,現(xiàn)在讓我們一起來(lái)看看吧!
1、import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class $ { public static void main(String... _) { String str = "我是一個(gè)java程序員"; String path = "d:/text.txt"; try { // 寫(xiě) save(path, str); // 讀 String txt = read(path); System.out.println(txt); } catch (IOException e) { e.printStackTrace(); } } private static void save(String path, String str) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(new File(path))); bw.write(str); bw.flush(); bw.close(); } private static String read(String path) throws IOException { BufferedReader br = new BufferedReader(new FileReader(new File(path))); StringBuffer buf = new StringBuffer(); while (br.ready()) { buf.append(br.readLine() + ""); } return buf.toString(); }}。
本文分享完畢,希望對(duì)大家有所幫助。
標(biāo)簽:
免責(zé)聲明:本文由用戶上傳,如有侵權(quán)請(qǐng)聯(lián)系刪除!