标题:[求助]怎样从键盘获取一个数字或者是字符?
只看楼主
xuyijin
Rank: 1
等 级:新手上路
威 望:1
帖 子:90
专家分:0
注 册:2006-4-13
得分:0 
我想问一下,下面的代码是什么意思?我不初学的,好多都不懂.
String s="";
BufferedReader in=new BufferedReader (new InputStreamReader(System.in));
s=in.readLine();
rows=Integer.parseInt(s);

初学java,希望各位大虾多多指教!!
2006-04-16 23:02
songdeguang
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-4-5
得分:0 
支持楼上的  我也不懂,能看明白的给讲一下

STUDY AND STUDY—JAVA
2006-04-17 13:08
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
得分:0 
String s="";//定义一个字符串对象
BufferedReader in=new BufferedReader (new InputStreamReader(System.in));//从标准输入构造一个缓冲字符读取器
s=in.readLine();//把读到的一行字符串赋给s
rows=Integer.parseInt(s);//把s转换成整型数据

可惜不是你,陪我到最后
2006-04-17 16:31
xuyijin
Rank: 1
等 级:新手上路
威 望:1
帖 子:90
专家分:0
注 册:2006-4-13
得分:0 
谢谢版主了!
我还想问一个问题:如何向文件中写入数据又如何从文件中读出数据?
我看了那个帮助,但是不能很好的理解!
好困惑!
希望版主和各位大是指点指点!小弟先谢过了!

初学java,希望各位大虾多多指教!!
2006-04-17 20:35
★王者至尊★
Rank: 1
等 级:新手上路
帖 子:528
专家分:0
注 册:2006-3-28
得分:0 

参考这个代码:
----------------------------------------------------
import java.io.*;
class fileWriteInfo {
void writeInfo()throws IOException{
int size=0;
byte b[]=new byte[6];
FileInputStream fin=new
FileInputStream("c:/java/abc.txt,true");
System.out.println("yes!");

FileOutputStream fout=new
FileOutputStream("c:/java/abc.txt,true");
try{
size=fin.available();
System.out.println("file size = "+size);

System.out.println("\nSkip the size :");
fin.skip(size);
System.out.print("Enter 6 chars: ");
for(int i=0;i<6;i++)
b[i]=(byte)System.in.read( );

fout.write(b);
}catch(IOException e){
System.out.print("file IOException!");
}finally{ fout.close( ); }
}
}

public class ReadAndWriteText {
public static void main(String args[])throws Exception {
fileWriteInfo obj=new fileWriteInfo ();
try{
obj.writeInfo();
}
catch(FileNotFoundException e) {
System.out.println("File not found : "+e);
throw e;
}catch(IOException e) {
System.out.println("File not found : "+e);
e.printStackTrace( );}

}
}


------Java 爱好者,论坛小混混,学习中------
2006-04-17 20:48
cyccn
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-16
得分:0 
System.err.out


输出 可能可以

你可以试试

2006-05-26 15:31



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-57761-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.531113 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved