導航:首頁 > 數據處理 > 怎麼讀取文件內數據

怎麼讀取文件內數據

發布時間:2023-09-19 00:59:07

㈠ java中怎樣從文件中讀取數據

分為讀位元組,讀字元兩種讀法x0dx0a◎◎◎FileInputStream 位元組輸入流讀文件◎◎◎x0dx0apublic class Maintest {x0dx0ax0dx0apublic static void main(String[] args) throws IOException {x0dx0ax0dx0aFile f=new File("G:\\just for fun\\xiangwei.txt");x0dx0ax0dx0aFileInputStream fin=new FileInputStream(f);x0dx0ax0dx0abyte[] bs=new byte[1024];x0dx0ax0dx0aint count=0;x0dx0awhile((count=fin.read(bs))>0)x0dx0a{x0dx0ax0dx0aString str=new String(bs,0,count);//反復定義新變數:每一次都 重新定義新變數,接收新讀取的滾雹數據x0dx0ax0dx0aSystem.out.println(str);//反復輸出新變數:察槐每一次都 輸出重大沒帆新定義的新變數x0dx0a}x0dx0afin.close();x0dx0a}x0dx0a}x0dx0ax0dx0a◎◎◎FileReader 字元輸入流讀文件◎◎◎x0dx0apublic class Maintest {x0dx0apublic static void main(String[] args) throws IOException {x0dx0ax0dx0aFile f=new File("H:\\just for fun\\xiangwei.txt");x0dx0ax0dx0aFileReader fre=new FileReader(f);x0dx0ax0dx0aBufferedReader bre=new BufferedReader(fre);x0dx0ax0dx0aString str="";x0dx0awhile((str=bre.readLine())!=null)//●判斷最後一行不存在,為空x0dx0a{x0dx0aSystem.out.println(str);x0dx0a}x0dx0abre.close();x0dx0a fre.close();x0dx0ax0dx0a}x0dx0ax0dx0a}

閱讀全文

與怎麼讀取文件內數據相關的資料

熱點內容
修腳技術多少錢一個月 瀏覽:629
康奈斯產品有哪些 瀏覽:101
廣東中煙駐點市場在哪裡 瀏覽:317
為什麼理財產品下滑 瀏覽:281
做天潤牛奶代理怎麼樣 瀏覽:811
手機數據線哪個網站批發 瀏覽:858
手機如何測試移動數據網速多少 瀏覽:223
如何做一個好的網店代理商 瀏覽:413
蘋果手機還原怎麼恢復數據 瀏覽:849
貴州茅台的企業產品標准有哪些 瀏覽:285
加工中心點孔程序極坐標怎麼用 瀏覽:752
華為換機大師怎麼導數據半天不動 瀏覽:106
高端美容小程序開發怎麼樣 瀏覽:43
mdf照明技術叫什麼 瀏覽:229
怎麼生成交易裝備的村民 瀏覽:351
哪裡可以學習柴油技術 瀏覽:416
蝦稻米市場前景怎麼樣 瀏覽:349
煙台海產品批發市場在哪裡 瀏覽:216
gbex交易所在哪裡 瀏覽:951
如何快速交易模型 瀏覽:247