java编写一个程序,从键盘输入一串字符,从屏幕输出并将其存入a.txt文件中。 JAVA利用标准输入法从键盘输入字符,并将输入的字符写到文本...

\u7f16\u5199\u4e00\u4e2aJava\u5e94\u7528\u7a0b\u5e8f\uff0c\u8bfb\u53d6\u4ece\u952e\u76d8\u8f93\u5165\u7684\u4e00\u884c\u6587\u672c\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u6587\u4ef6line.txt\u4e2d\uff0c\u5f53\u7528\u6237\u8fd0\u884c\u7a0b\u5e8f\u65f6\uff0c\u9700\u8981\u8f93

import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.util.Scanner;public class TestOutPut{public static void main(String[] args) {Scanner scanner = new Scanner(System.in);String inputStr = scanner.nextLine();File file = new File("line.txt");FileOutputStream fileOut;try {fileOut = new FileOutputStream(file);fileOut.write(inputStr.getBytes());} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;public class InputStreamReaderTest {
public static void main(String[] args) {
BufferedReader br=null;
BufferedWriter bw=null;
String str=null;
FileReader fr= null;
FileWriter fw = null;
String path ="d:/fuck.txt";
int c=0;

br=new BufferedReader(new InputStreamReader(System.in));//\u4e0d\u77e5\u9053\u8fd9\u662f\u4e0d\u662f\u7f13\u51b2\u8f93\u5165\u6d41
System.out.print("\u8bf7\u8f93\u5165\u6570\u636e:");
try {//
str=br.readLine();//\u4ece\u952e\u76d8\u4e0a\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u4ee5\u56de\u8f66\u7ed3\u675f\u3002
fw = new FileWriter(path);
bw = new BufferedWriter(fw);
bw.write("\u592a\u9633\u51fa\u6765\u4e1c\u65b9\u4eae\uff0c\u5c71\u70ae\u5565\u6837\u6211\u5565\u6837\\n\u2026\u2026");
while(str != null){//\u7528\u4e86\u5faa\u73af\u53ef\u4ee5\u591a\u8f93\u5165\u51e0\u6b21\u3002
if(str.equalsIgnoreCase("exit")){
break;
}
System.out.println("\u4ece\u952e\u76d8\u4e0a\u8f93\u5165\u7684\u6570\u636e\u4e3a\uff1a" + str);//\u8f93\u51fa\u5c4f\u5e55
bw.write(str);//\u5199\u5230\u6587\u672c
//bw.newLine();
System.out.print("\u8bf7\u8f93\u5165\u6570\u636e:");
str=br.readLine();
}
bw.flush();
System.out.println("end");

}catch(FileNotFoundException e){

} catch (IOException e) { } finally{
try {
if(br != null)
br.close();
} catch (IOException e) {

}
try {
bw.close();
} catch (IOException e) {

}
try {
fw.close();
} catch (IOException e) {

}
}

try {
fr = new FileReader(path);
while((c = fr.read())!= -1){//\u4ece\u6587\u672c\u8bfb\u53d6
System.out.print((char)c);
}
System.out.println();
} catch (FileNotFoundException e){

} catch (Exception e) {

}



}
}

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.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();
}
}
}

你是准备使用输出流写得么??

  • 濡備綍Java缂栧啓鍐掓场绋嬪簭,瑕佹眰鏄浠庨敭鐩杈撳叆涓涓姝f暣鏁皀琛ㄧず涓暟,鐒跺悗杈
    绛旓細import java.io.BufferedReader;import java.io.InputStreamReader;public class MaoPaoPaiXu {public static void main(String[] args) throws Exception {System.out.println("璇疯緭鍏ヨ杈撳叆鐨勬鏁存暟涓暟锛");BufferedReader br = new BufferedReader(new InputStreamReader(System.in));String num = ...
  • java瀹為獙:缂栧啓绋嬪簭,浠庨敭鐩涓婅緭鍏ヤ袱涓暟銆傚皢绗涓涓鏁伴櫎浠ョ浜屼釜鏁板苟鏄 ...
    绛旓細import java.awt.*;import javax.swing.*;import java.awt.event.*;public class FuctJFrame extends JFrame implements ActionListener{ / / private static final long serialVersionUID = 1L;JLabel jlabel=new JLabel("璇疯緭鍏ヤ袱涓暟:");JLabel jlabel1=new JLabel();JTextField jtextfield=new...
  • 缂栧啓涓涓狫ava搴旂敤绋嬪簭,瑕佹眰浠庨敭鐩杈撳叆涓や釜鏁存暟,璁$畻杩欎袱涓暟鎹箣鍜...
    绛旓細鍒╃敤Java搴旂敤绋嬪簭缂栧啓瑕佹眰杈撳叆涓や釜鏁存暟骞惰绠椾袱涓暟鎹箣鍜屽叿浣撴搷浣滄楠ゅ涓嬶細import java.util.Scanner public class Test { public static void main(String[] args) { System.out.print("璇疯緭鍏ョ涓涓鏁存暟锛")Scanner s=new Scanner(System.in)int a=s.nextInt()System.out.print("璇疯緭鍏ョ浜屼釜...
  • 缂栧啓java绋嬪簭瀹炵幇浠ヤ笅鍔熻兘:浠庨敭鐩杈撳叆瀛︾敓濮撳悕銆佸鍙枫佹垚缁,骞朵繚瀛樺埌鏂...
    绛旓細public class test3{ public static void main(String []args) { String FilePath="d:\\javaTest\\output.txt";writeAll(FilePath);} private static void writeAll(String filePath) { File output = new File(filePath);String outputStr = "";Scanner sc = new Scanner(System.in);System...
  • java杈撳叆杈撳嚭绋嬪簭浠g爜
    绛旓細Java IO妯″瀷 :Java鐨IO妯″瀷璁捐闈炲父浼樼锛屽畠浣跨敤Decorator妯″紡锛屾寜鍔熻兘鍒掑垎Stream锛屾偍鍙互鍔ㄦ佽閰嶈繖浜汼tream锛屼互渚胯幏寰楁偍闇瑕佺殑鍔熻兘銆備緥濡傦紝鎮ㄩ渶瑕涓涓鍏锋湁缂撳啿鐨勬枃浠惰緭鍏ユ祦锛屽垯搴斿綋缁勫悎浣跨敤FileInputStream鍜孊ufferedInputStream銆傝緭鍏ユ祦锛圛nput Stream锛夛細绋嬪簭浠杈撳叆娴佽鍙栨暟鎹簮銆傛暟鎹簮鍖呮嫭澶栫晫(閿洏銆佹枃浠躲...
  • 缂栧啓涓涓▼搴,浠庨敭鐩杈撳叆5涓暟,姹傚嚭杩5涓暟涔嬪拰鍙婂钩鍧囧?
    绛旓細鍥炵瓟锛歩nt Sum = 0; for (int i = 1; i <= 5; i++) { Console.WriteLine("璇疯緭鍏ョ"+i+"鏁"); //鍦ㄨ繖閲屼綘鍙互瀵硅緭鍏ョ殑鏁拌繘琛岄獙璇 Sum +=int.Parse ( Console.ReadLine()); } Console.WriteLine("浣犺緭鍏ョ殑浜斾釜鏁扮殑鍜屼负:{0} 骞冲潎鍊间綅:{1}", Sum, (double)Sum / 5); Consol...
  • java璇缂栧啓涓绋嬪簭,鍙鐢遍敭鐩杈撳叆涓涓鏁存暟,鐒跺悗鍒ゆ柇璇ユ暟鍊兼槸姝f暟杩樻槸璐熸暟...
    绛旓細import java.util.Scanner; public class TestJT { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("璇疯緭鍏ユ暣鏁"); int input= sc.nextInt(); if(input>=0){ System.out.println("浣犺緭鍏ョ殑鏄鏁"); }else{ ...
  • 缂栧啓涓涓猨ava绋嬪簭,閫氳繃閿洏杈撳叆涓や釜鏁存暟,姹備袱鏁扮殑鍜岀殑绋嬪簭銆
    绛旓細閫氳繃閿洏杈撳叆涓や釜鏁存暟锛屾眰涓ゆ暟鐨勫拰鐨凧ava绋嬪簭濡備笅鍥炬墍绀猴細缂栧啓Java绋嬪簭鏃讹紝搴旀敞鎰忎互涓嬪嚑鐐癸細澶у皬鍐欐晱鎰燂細Java鏄ぇ灏忓啓鏁忔劅鐨勶紝杩欏氨鎰忓懗鐫鏍囪瘑绗ello涓巋ello鏄笉鍚岀殑銆傜被鍚嶏細瀵逛簬鎵鏈夌殑绫绘潵璇达紝绫诲悕鐨勯瀛楁瘝搴旇澶у啓銆傚鏋滅被鍚嶇敱鑻ュ共鍗曡瘝缁勬垚锛岄偅涔堟瘡涓崟璇嶇殑棣栧瓧姣嶅簲璇ュぇ鍐欙紝渚嬪 MyFirstJavaClass銆傛柟娉...
  • java浠庨敭鐩渚濇杈撳叆10涓鏁存暟,瀛樻斁鍦ㄦ暟缁勪腑,姣忚緭鍏涓涓鏁存暟灏辫繘琛屾帓搴...
    绛旓細鎸夌収浣犵殑瑕佹眰渚濇杈撳叆10涓鏁存暟,姣忚緭鍏涓涓鏁存暟灏辫繘琛屾帓搴忕殑Java绋嬪簭濡備笅 import java.util.Scanner;public class J { public static void bubblesort(int[] arr,int n){ for(int i=0;i<n-1;i++){ for(int j=0;j<n-1-i;j++){ if(arr[j]>arr[j+1]){ int temp=arr[j];arr[...
  • 浠庨敭鐩杈撳叆涓涓插瓧绗︿覆,缂栧啓涓涓猨ava绋嬪簭瀹炵幇缁熻,杈撳嚭鏈夊嚑涓ぇ鍐欏瓧姣...
    绛旓細/*** 璇ユ柟娉曡繑璐ц瀛楃涓茬殑鍚勪釜瀛楃鍒涓涓鏁扮粍閲* 杩欓噷鎴戞墦绠楃敤ArrayList鐨勶紝浣嗘槸浠栧彧鑳戒繚瀛樹负Object绫诲瀷* 灏辨槸涓嶇煡閬撴庝箞鎶奜bject杞崲涓篶har,鎵浠ワ紝杩欓噷灏辩敤char[]*/public char[] charsOfString(String s){   char[] list = new char[s.length()];   for (int i...
  • 扩展阅读:java自学入门免费网站 ... 编写简单的java程序 ... java编程零基础入门 ... java一键生成app程序 ... 初学编程必背50个 ... java键盘输入 ... 入门的java游戏小程序 ... 写一个简单的java程序 ... 如何编写一个简单的java ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网