java编写一个程序,从键盘输入一串字符,从屏幕输出并将其存入a.txt文件中。
展开全部
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Write{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要输入的字符");
String str=sc.next();
System.out.println("你输入的字符为");
System.out.println(str);
try {
BufferedWriter buff = new BufferedWriter(new FileWriter("D:\\chat File\\a.txt"));
buff.write(str);
buff.flush();
buff.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Write{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入要输入的字符");
String str=sc.next();
System.out.println("你输入的字符为");
System.out.println(str);
try {
BufferedWriter buff = new BufferedWriter(new FileWriter("D:\\chat File\\a.txt"));
buff.write(str);
buff.flush();
buff.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class OutputA {
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
System.out.println("string's value is : "+s);
try {
BufferedWriter bw=new BufferedWriter(new FileWriter("d:\\a.txt"));
bw.write(s);
bw.flush();
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class OutputA {
public static void main(String [] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
System.out.println("string's value is : "+s);
try {
BufferedWriter bw=new BufferedWriter(new FileWriter("d:\\a.txt"));
bw.write(s);
bw.flush();
bw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你是准备使用输出流写得么??
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询