자바 입력 의 몇 가지 상황
                                            
 2880 단어  IO
                    
package JavaTest;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Scanner;
public class InputDemo {
	
	public static void main(String[] args) throws IOException{
		//Demo_1();
		
		//Demo_2();
		
		//Demo_3();
		
		Scanner scr=new Scanner(System.in);
		BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\xuan.txt"));
		System.out.println("   ");
		String name=scr.next();
		System.out.println("result:"+name);
		bw.write(name);
		bw.newLine();
		bw.flush();
		bw.close();
		
	}
	public static void Demo_3() throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
		String line=null;
		while((line=br.readLine())!=null){
			if(line.equals("#")){
				break;
			}
			//System.out.println("result:"+line);
			bw.write("result:"+line+"\r
");
			//bw.newLine();
			bw.flush();
		}
	}
	
	/////////////////////////////
	public static void Demo_2() throws IOException {
		//    
		StringBuilder sb=new StringBuilder();
		//       
		InputStream in=System.in;
		//            ,     
		int ch=0;
		while((ch=in.read())!=-1){
			if(ch=='\r')
				continue;
			if(ch=='
'){
				String temp=sb.toString();
				if(temp.equals("#")){
				    break;
				}
				System.out.println("     :"+temp);
				sb.delete(0, sb.length());
			}else{
				sb.append((char)ch);//         (  )  
				//System.out.println("result:"+ch);
			}
		}
	}
	/////////////////////////////////////
	public static void Demo_1() throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
		int len=0;
		while((len=br.read())!=-1){
			System.out.println("      :"+(char)len);
		}
		br.close();
	}
	
}
첫 번 째: (정수 입력)
int a=System.in.read();
두 번 째: (만능 입력)
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
java.util.Scanner sc = new java.util.Scanner(System.in);
int b = sc.nextInt();
public class InputSemo {
	
	public static void main(String args[]){
		Scanner scanner=new Scanner(System.in);
		System.out.println("   1");
		int num=scanner.nextInt();
		System.out.println("   2");
		String string=scanner.nextLine();
		System.out.println("   3");
		String str =scanner.next();
		if(num==0){
			System.out.println("   ");
		}
		if(string==null){
			System.out.println("   ");
		}
		if(str==null){
			System.out.println("   ");
		}
		
		System.out.println(num+"=="+string+"=="+str);
	}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
java 입출력 I/O스트림(stream) 자바에서 입출력을 수행하려면 두 대상을 연결하고 데이터를 전송할 수 있는 무언가가 필요한데 이것을 스트림(stream)이라고 정의했다. 스트림은 단방향 통신만 가능하기 때문에 하나의 스트림으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.