Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java SE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 IO小程序,不会做,请教(将键盘上输入的字符写到文件)
肖升





发贴: 1
积分: 0
于 2005-08-31 11:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
请尽量使用准确的文字描述作为标题

Original subject :
IO小程序,不会做,请教


各位高手们,请赐教啊.
自我自学爪哇来,遇到了很多的问题,可是苦于身边没有一个懂的人,想问也没地方问去.现在发现问题如果再不解决就要影响到后面的效果了,所以特上网来求助于各位大侠们.请大侠们不要认为问题太简单而不帮我噢。

这是我的第一个问题,各位有心之士,可跟贴或发邮件给我,jszhaofei@163.com

题目:将键盘上输入的一串字符写到文本文件中.
我的程序为:

public class Getwrite{
public static void main(String args[]) throws IOException{
try{
File out=new File("a.txt");
int s;
FileOutputStream fos=new FileOutputStream(out);
InputStreamReader ir;
BufferedReader in;
ir=new InputStreamReader(System.in);
while((s=ir.read())!=-1)
fos.write(s);
}catch(FileNotFoundException e){
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}
}
}


why edited on 2005-09-05 21:48

作者 Re:IO小程序,不会做,请教 [Re:肖升]
zhangp_happy





发贴: 22
积分: 0
于 2005-09-04 11:14 user profilesend a private message to usersend email to zhangp_happysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
根据楼主的题目题目:将键盘上输入的“一串字符”写到文本文件中.
我写好了一个程序,尽量与楼主的相似如下:
import java.io.*;

class GetWrite
{
static void write(InputStream in)
{
try
{
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
s = br.readLine();
PrintStream p = new PrintStream(new FileOutputStream("out.txt"));
p.println(s);
p.close();
br.close();
}
catch(Exception e)
{
System.err.print(e);
}
}
public static void main(String[] args)
{
write(System.in);
}
}

楼主的程序里有很多小的问题,如果楼主想就这个问题讨论可以与我联系:zhangp_happy@yahoo.com.cn


why edited on 2005-09-05 21:44

作者 Re:IO小程序,不会做,请教 [Re:肖升]
zzmsotao





发贴: 2
积分: 0
于 2005-09-05 18:15 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
怎么这两个程序都错了啊


作者 Re:IO小程序,不会做,请教 [Re:肖升]
zcjl

涅槃



发贴: 537
积分: 65
于 2005-09-05 20:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
public class GetWrite {
public static void main(String args[]) throws Exception {
OutputStream os = null;
InputStream is = null;
try {
os = new BufferedOutputStream(new FileOutputStream("a.txt"));
is = new BufferedInputStream(System.in);
int i;
while((i = is.read()) != -1) {
if(i == (int)'\n') { // 设置退出条件,这里为回车符
break;
}
os.write(i);
}
} catch (Exception e) {
System.out.println(e);
} finally {
is.close();
os.close();
}
}
}


zcjl edited on 2005-09-05 20:09


flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923