RT~上次看到一位朋友的问题,下去试了下,虽完成了,但有一行代码不大明白,请大虾们指点~import java.io.*;
/*
* 键盘输入姓,文件输出相邻的100个字
*/
public class TestIO {
public static void main(String[] args){
int c = 0;
InputStreamReader isr=new InputStreamReader(System.in);//疑惑处
try {
c=isr.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fun(c);
}
public static void fun(int c){
FileWriter fw = null;
try {
fw = new FileWriter("F:\\练习\\text.txt");
for(int i=c-50;i<=c+50;i++){
fw.write((char)i);
}
fw.close();
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("文件写入错误");
System.exit(-1);
}
}
}
/*
* 键盘输入姓,文件输出相邻的100个字
*/
public class TestIO {
public static void main(String[] args){
int c = 0;
InputStreamReader isr=new InputStreamReader(System.in);//疑惑处
try {
c=isr.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
fun(c);
}
public static void fun(int c){
FileWriter fw = null;
try {
fw = new FileWriter("F:\\练习\\text.txt");
for(int i=c-50;i<=c+50;i++){
fw.write((char)i);
}
fw.close();
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("文件写入错误");
System.exit(-1);
}
}
}
解决方案 »
- 下面这段代码是从书上抄的,可是为什么在执行时,提示下面的错误,求解决
- 新手小程序求解错误
- windows cmd下运行java程序
- 如何用循环输出01到99。。。注意不是1到99.。。
- 关于Activex bridge for JavaBeans
- java.sql.SQLException: Value conflicts occurs
- 从书上拷贝下来的,怎么老是“can't find the file”,
- 怎样使一个按钮成为默认按钮?
- 菜鸟提问:java与c++在功能上有什么区别?java有什么优势?
- 各位大佬,请问这段注释为什么会报错啊???
- tomcat不能部署问题!求真相
- 求一面试题解
= new BufferedReader(new InputStreamReader(System.in));
摘录自api[c,c+99]是一百没错,但当中包含了输入的那个姓