希望这个对初学的JAVA学者有帮助。
我是先学了C,C++之后才涉猎JAVA的,因为它很受欢迎,总得了解一下
从键盘接收数据:
1、
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter a line:");
System.out.println(stdin.readLine());
2、Scanner cin = new Scanner(System.in);
String s = new String();
s=cin.nextLine();
System.out.println(s);
3、也可以用System.in.read()来实现
4、从文件里读取数据
BufferedReader in =
new BufferedReader(
new FileReader("F://nepalon//TestIO.java"));
String s, s2 = new String();
while((s = in.readLine()) != null)
s2 += s + "/n";
in.close();//注意关闭文件
5、从对象中读取数据
StringTokenizer st= newStringTokenizer(s);
int a=Integer.praseInt(st.nextToken());
7、输出到屏幕
System.out.print();
System.out.println();
8、输出到文件
我是先学了C,C++之后才涉猎JAVA的,因为它很受欢迎,总得了解一下
从键盘接收数据:
1、
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter a line:");
System.out.println(stdin.readLine());
2、Scanner cin = new Scanner(System.in);
String s = new String();
s=cin.nextLine();
System.out.println(s);
3、也可以用System.in.read()来实现
4、从文件里读取数据
BufferedReader in =
new BufferedReader(
new FileReader("F://nepalon//TestIO.java"));
String s, s2 = new String();
while((s = in.readLine()) != null)
s2 += s + "/n";
in.close();//注意关闭文件
5、从对象中读取数据
StringReader in2 = new StringReader(s2);
int c;
while((c = in2.read()) != -1)
System.out.println((char)c);
in2.close();
StringTokenizer st= newStringTokenizer(s);
int a=Integer.praseInt(st.nextToken());
7、输出到屏幕
System.out.print();
System.out.println();
8、输出到文件
try{
BufferedReader in4 =
new BufferedReader(
new StringReader(s2));
PrintWriter out1 =
new PrintWriter(
new BufferedWriter(
new FileWriter("F://nepalon// TestIO.out")));
int lineCount = 1;
while((s = in4.readLine()) != null)
out1.println(lineCount++ + ":" + s);
out1.close();
in4.close();
}
catch(EOFException ex){
System.out.println("End of stream");
}
![](/Editor/FCKeditor/editor/images/smiley/msn/tounge_smile.gif)