學(xué)習(xí)筆跡
好記性不如爛筆頭!
BlogJava
首頁(yè)
新隨筆
聯(lián)系
管理
隨筆-153 評(píng)論-235 文章-19 trackbacks-0
簡(jiǎn)單的讀寫(xiě)文件
?
import
?java.io.File;
import
?java.io.FileInputStream;
import
?java.io.FileNotFoundException;
import
?java.io.IOException;
import
?java.nio.ByteBuffer;
import
?java.nio.channels.FileChannel;
public
?
class
?ReadAString?
{
????
/**?*/
/**
?????*?
@param
?args
?????
*/
????
public
?
static
?
void
?main(String[]?args)?
{
????????
//
?TODO?自動(dòng)生成方法存根
????????File?aFile?
=
?
new
?File(
"
d:/test.txt
"
);
????????FileInputStream?inFile?
=
?
null
;
????????
????????
try
?
{
????????????inFile?
=
?
new
?FileInputStream(aFile);
????????}
?
catch
(FileNotFoundException?e)?
{
????????????e.printStackTrace(System.err);
????????????System.exit(
1
);
????????}
????????
????????FileChannel?inChannel?
=
?inFile.getChannel();
????????ByteBuffer?buf?
=
?ByteBuffer.allocate(
48
);
????????
//
String?buf?=?"";
????????
try
?
{
????????????
while
(inChannel.read(buf)?
!=
?
-
1
)?
{
????????????????System.out.println(
"
String?read:?
"
+
????????????????????????((ByteBuffer)(buf.flip())).asCharBuffer().toString());
????????????????buf.clear();
????????????}
????????????System.out.println(
"
EOF?readched.
"
);
????????????inFile.close();
????????}
?
catch
(IOException?e)?
{
????????????e.printStackTrace(System.err);
????????????System.exit(
1
);
????????}
????????
????????System.exit(
0
);
????}
}
posted on 2006-11-11 15:40
流浪汗
閱讀(379)
評(píng)論(0)
編輯
收藏
所屬分類(lèi):
Java
新用戶注冊(cè)
刷新評(píng)論列表
只有注冊(cè)用戶
登錄
后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
相關(guān)文章:
必讀:徹底明白Java的IO系統(tǒng)---JAVA之精髓IO流!
[轉(zhuǎn)]Spring2.5的新特性
[轉(zhuǎn)載]Java開(kāi)發(fā)技術(shù)十年的回顧與展望
MD5
簡(jiǎn)單的讀寫(xiě)文件
<
2025年6月
>
日
一
二
三
四
五
六
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
留言簿
(14)
給我留言
查看公開(kāi)留言
查看私人留言
隨筆分類(lèi)
AJAX(1)
algorithm(1)
C/C++(2)
Design paterns/UML(1)
Eclipse(2)
HTML(14)
JAVA/J2EE(24)
Linux(24)
Lucene(8)
mmseg4j(2)
MySQL(9)
OpenSource(12)
oracle(7)
Other(2)
Server(4)
Spring(7)
Tomcat(11)
名詞解釋(5)
寓言(1)
小技巧(3)
感情天地(2)
搞笑鏈接(1)
清理(6)
疑難雜癥(4)
隨筆檔案
2010年2月 (3)
2010年1月 (1)
2009年10月 (1)
2009年4月 (1)
2008年10月 (1)
2008年9月 (4)
2008年8月 (6)
2008年7月 (10)
2008年6月 (8)
2008年5月 (7)
2008年4月 (4)
2008年3月 (9)
2008年2月 (1)
2008年1月 (3)
2007年12月 (6)
2007年11月 (5)
2007年10月 (15)
2007年9月 (9)
2007年8月 (14)
2007年7月 (6)
2007年6月 (2)
2007年5月 (6)
2007年4月 (8)
2007年3月 (13)
2007年2月 (1)
2006年12月 (3)
2006年11月 (7)
文章分類(lèi)
Java(5)
linux(3)
lucene(1)
other
Search(5)
學(xué)習(xí)鏈接(1)
收藏夾(2)
項(xiàng)目(1)
文章檔案
2008年7月 (5)
2008年3月 (5)
2008年2月 (1)
2007年10月 (2)
2007年4月 (2)
2006年12月 (1)
2006年11月 (2)
新聞分類(lèi)
java(1)
新聞檔案
2008年7月 (1)
收藏夾
Java(9)
solr(1)
科技(1)
友情鏈接
vootoo 電視劇網(wǎng)
中文 MySQL.CN 論壇
我的javaeye博客
我的個(gè)人博客
老丘的 Blog
同學(xué)鏈接
學(xué)習(xí)鏈接
css javascript(rlog)
好css 與 javascript
jobchanceleo(職業(yè)生涯顧問(wèn)Leo)
lhwork
max(struts2)
qclass(java/j2ee)
Unmi(Quartz)
willpower88
推薦系統(tǒng)
比較有深度的"推薦系統(tǒng)"相關(guān)的文章
蛟龍居
專(zhuān)注Groovy & Grails
最新隨筆
1.?css 實(shí)現(xiàn)鼠標(biāo)移到上面背景變色
2.?css 標(biāo)簽 a 的 hover 是否有效與出現(xiàn)的順序有關(guān)
3.?Nginx Location 語(yǔ)法,與簡(jiǎn)單配置
4.?linux下top命令參數(shù)解釋
5.?中文分詞 mmseg4j-1.8 版發(fā)布
6.?中文分詞 mmseg4j 1.7.2 版發(fā)布
7.?此博客很少更新!
8.?試用 code highlight (SyntaxHighlighter)
9.?linux 解壓 tgz
10.?solr分發(fā)問(wèn)題 rsync:link_stat "snapshot.20080820124136/." (in solr) failed: No such file or directory (2)
搜索
積分與排名
積分 - 559971
排名 - 86
最新評(píng)論
1.?re: ssh 免密碼登錄
不要密碼賬號(hào)
--韓有中
2.?re: ssh 免密碼登錄
怎么上不了網(wǎng)
--韓有中
3.?re: ant build 出現(xiàn) warning modified in the future
太感謝了
--孫
4.?re: linux 解壓 tgz
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--elesos
5.?re: linux 解壓 tgz
評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
--elesos
閱讀排行榜
1.?linux 解壓 tgz(46249)
2.?ORA-01461: can bind a LONG value only for insert into a LONG column(25285)
3.?windows media player 11 破解(24020)
4.?U盤(pán)中毒,文件夾被隱藏,同時(shí)生成與文件夾相同名稱(chēng)的*.exe文件.(20419)
5.?spring 依賴注入到直接new 對(duì)象(15437)
6.?xml 轉(zhuǎn)義符(15424)
7.?ssh 免密碼登錄(13745)
8.?centos 配置 ssh(12572)
9.?Nginx Location 語(yǔ)法,與簡(jiǎn)單配置(12025)
10.?整數(shù)或小數(shù)正則表達(dá)式問(wèn)題(javascript)(11056)
評(píng)論排行榜
1.?U盤(pán)中毒,文件夾被隱藏,同時(shí)生成與文件夾相同名稱(chēng)的*.exe文件.(40)
2.?windows media player 11 破解(32)
3.?ORA-01461: can bind a LONG value only for insert into a LONG column(14)
4.?語(yǔ)言欄無(wú)法顯示,不顯示怎么辦?(9)
5.?查看開(kāi)機(jī)時(shí)間(9)
Powered by:
博客園
模板提供:
滬江博客
Copyright ©2025 流浪汗
主站蜘蛛池模板:
巧家县
|
宣城市
|
孝昌县
|
庆阳市
|
保靖县
|
舒城县
|
舟山市
|
铜鼓县
|
香格里拉县
|
财经
|
绥宁县
|
承德市
|
明溪县
|
渑池县
|
灵山县
|
尤溪县
|
沁水县
|
洞口县
|
准格尔旗
|
三明市
|
莫力
|
韶关市
|
清水河县
|
民乐县
|
新兴县
|
新干县
|
密云县
|
思南县
|
玉门市
|
金坛市
|
祁连县
|
瓦房店市
|
巴马
|
新和县
|
宿州市
|
景洪市
|
盱眙县
|
三穗县
|
江城
|
滦平县
|
安达市
|