您好,登錄后才能下訂單哦!
小編給大家分享一下Java常見(jiàn)IO面試題有哪些,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
1:什么是流?
字符串分解==============OutStream==========>write()方法寫(xiě)到文件中
2:描述I/O流的基本接口和類的結(jié)構(gòu)
InputStream
OutputStream
3:代碼示例:如何使用URL流來(lái)進(jìn)行輸入輸出
try { imageSource = new URL("http://mysite.com/~info"); } catch (MalformedURLException e) { }
4:什么是Unicode?
是一種字符的編碼方式
5:代碼示例:如何使用Reader和Writer來(lái)進(jìn)行輸入輸出
InputStreamReader ir = new InputStreamReader(System.in); OutStreamReader or = new OutStreamReader(System.in);
6:什么是可序列化?如何實(shí)現(xiàn)可序列化?
表示一個(gè)數(shù)據(jù)可以按流式輸出
實(shí)現(xiàn)java.io.Serializable接口
7:代碼示例:如何讀寫(xiě)對(duì)象流
//讀 try { String str = "123"; FileOutputStream f = new FileOutputStream("test.txt"); ObjectOutputStream s = new ObjectOutputStream(f); s.writeObject(str); f.close(); }catch(Exception e) { e.printStackTrace(); }
//寫(xiě) try { FileInputStream f = new FileInputStream("test.txt"); ObjectInputStream s = new ObjectInputStream(f); str =(String)s.readObject(); f.close(); }catch(Exception e){ e.printStackTrace(); }
8:簡(jiǎn)述File類的基本功能
處理文件和獲取文件信息,文件或文件夾的管理
除了讀寫(xiě)文件內(nèi)容其他的都可以做
9:代碼示例:如何使用隨機(jī)文件讀寫(xiě)類來(lái)讀寫(xiě)文件內(nèi)容
RW表示文件時(shí)可讀寫(xiě)的 讀: try{ RandomAccessFile f = new RandomAccessFile("test.txt", "rw"); long len = 0L; long allLen = f.length(); int i = 0; while (len < allLen) { String s = f.readLine(); if (i > 0) { col.add(s); } i++; //游標(biāo) len = f.getFilePointer(); } }catch(Exception err){ err.printStackTrace(); } 寫(xiě): try{ RandomAccessFile f = new RandomAccessFile("test.txt", "rw"); StringBuffer buffer = new StringBuffer("\n"); Iterator it = col.iterator(); while (it.hasNext()) { buffer.append(it.next() + "\n"); } f.writeUTF(buffer.toString()); }catch(Exception err){ err.printStackTrace(); }
10:代碼示例:如何使用流的基本接口來(lái)讀寫(xiě)文件內(nèi)容
try{ DataInputStream in = new DataInputStream( new BufferedInputStream( new FileInputStream("Test.java") ) ); while ((currentLine = in.readLine()) != null){ System.out.println(currentLine); } }catch (IOException e){ System.err.println("Error: " + e); }
以上是“Java常見(jiàn)IO面試題有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(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)容。