Java常見IO面試題有哪些

小編給大家分享一下Java常見IO面試題有哪些,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

目前成都創(chuàng)新互聯(lián)公司已為上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、廣宗網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

1:什么是流?

字符串分解==============OutStream==========>write()方法寫到文件中

2:描述I/O流的基本接口和類的結(jié)構(gòu)

InputStream

OutputStream

3:代碼示例:如何使用URL流來進(jìn)行輸入輸出

try {
 
  imageSource = new URL("http://mysite.com/~info");
 
} catch (MalformedURLException e) {
 
}

4:什么是Unicode?

是一種字符的編碼方式

5:代碼示例:如何使用Reader和Writer來進(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:代碼示例:如何讀寫對(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();
 
}
//寫
 
try {
 
FileInputStream f = new FileInputStream("test.txt");
 
ObjectInputStream s = new ObjectInputStream(f);
 
str =(String)s.readObject();
 
f.close();
 
}catch(Exception e){
 
e.printStackTrace();
 
}

8:簡述File類的基本功能

處理文件和獲取文件信息,文件或文件夾的管理

除了讀寫文件內(nèi)容其他的都可以做

9:代碼示例:如何使用隨機(jī)文件讀寫類來讀寫文件內(nèi)容  

RW表示文件時(shí)可讀寫的
 
讀:
 
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();
 
  }
 
  
 
  寫:
 
  
 
  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:代碼示例:如何使用流的基本接口來讀寫文件內(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常見IO面試題有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)頁名稱:Java常見IO面試題有哪些
URL網(wǎng)址:http://bm7419.com/article34/pcspse.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)電子商務(wù)、微信小程序網(wǎng)站收錄、域名注冊云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計(jì)公司