“java”如何将输出结果放入文件中?
2个回答
展开全部
你改编一下
public class Prog50{
//定义学号
String[] number = new String[5];
public static void main(String[] args) throws Exception{
Prog50 stud = new Prog50();
stud.input();
stud.output();
}
void input() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//录入状态标识
boolean isRecord = true;
while(isRecord){
try{
for(int i=0;i<5;i++){
System.out.print("请输入学号:");
number[i] = br.readLine();
isRecord = false;
}catch(NumberFormatException e){
System.out.println("请输入一个数字!");
}
void output() throws IOException{
FileWriter fw = new FileWriter("E://java50//stud.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("No. ");
bw.newLine();
for(int i=0;i<5;i++){
bw.write(number[i]);
}
bw.close();
}
}
public class Prog50{
//定义学号
String[] number = new String[5];
public static void main(String[] args) throws Exception{
Prog50 stud = new Prog50();
stud.input();
stud.output();
}
void input() throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//录入状态标识
boolean isRecord = true;
while(isRecord){
try{
for(int i=0;i<5;i++){
System.out.print("请输入学号:");
number[i] = br.readLine();
isRecord = false;
}catch(NumberFormatException e){
System.out.println("请输入一个数字!");
}
void output() throws IOException{
FileWriter fw = new FileWriter("E://java50//stud.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("No. ");
bw.newLine();
for(int i=0;i<5;i++){
bw.write(number[i]);
}
bw.close();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询