当前位置: 技术问答>java相关
输入与输出流,小弟学业不精,想请教大家一下
来源: 互联网 发布时间:2015-08-24
本文导语: 我想做个函数将一个文件的内容输出到另外一个对象中,这个对象不一定是文件 static void fillObject (Object obj, String filepathname) throws Exception { Writer outstream = obj.OutputStream(); BufferedReader ko...
我想做个函数将一个文件的内容输出到另外一个对象中,这个对象不一定是文件
static void fillObject (Object obj, String filepathname)
throws Exception
{
Writer outstream = obj.OutputStream();
BufferedReader ko=new BufferedReader(new FileReader(filepathname));
.......
}
哈哈,我只会这么多,下面那些该怎么做呢?怎么能将一个reader流的东西,写到obj里面呢?
static void fillObject (Object obj, String filepathname)
throws Exception
{
Writer outstream = obj.OutputStream();
BufferedReader ko=new BufferedReader(new FileReader(filepathname));
.......
}
哈哈,我只会这么多,下面那些该怎么做呢?怎么能将一个reader流的东西,写到obj里面呢?
|
请问你写到Object里面之后做什么呢?下面是JAVA文档的例子代码
FileOutputStream ostream = new FileOutputStream("t.tmp");
ObjectOutputStream p = new ObjectOutputStream(ostream);
p.writeInt(12345);
p.writeObject("Today");
p.writeObject(new Date());
p.flush();
ostream.close();
读OBJECT
FileInputStream istream = new FileInputStream("t.tmp");
ObjectInputStream p = new ObjectInputStream(istream);
int i = p.readInt();
String today = (String)p.readObject();
Date date = (Date)p.readObject();
istream.close();
FileOutputStream ostream = new FileOutputStream("t.tmp");
ObjectOutputStream p = new ObjectOutputStream(ostream);
p.writeInt(12345);
p.writeObject("Today");
p.writeObject(new Date());
p.flush();
ostream.close();
读OBJECT
FileInputStream istream = new FileInputStream("t.tmp");
ObjectInputStream p = new ObjectInputStream(istream);
int i = p.readInt();
String today = (String)p.readObject();
Date date = (Date)p.readObject();
istream.close();
|
static void fillObject (Object obj, String filepathname)
throws Exception
{
Writer outstream = obj.OutputStream();
~~~~~~~~~~~~~~~~~~~好像object没有这样的方法
BufferedReader ko=new BufferedReader(new FileReader(filepathname));
.......
}
throws Exception
{
Writer outstream = obj.OutputStream();
~~~~~~~~~~~~~~~~~~~好像object没有这样的方法
BufferedReader ko=new BufferedReader(new FileReader(filepathname));
.......
}
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。