JAVA输出时把输出流的空格当做结束符号
输出helloteacher变成helloimportjava.io.*;importjava.util.Scanner;publicclassex{publicstat...
输出hello teacher变成hello
import java.io.*;
import java.util.Scanner;
public class ex {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
System.out.println("请输入");
String s = cin.next();
byte[] b = s.getBytes();
try {
FileOutputStream out = new FileOutputStream("ex.txt");
System.out.println("结果已打印");
out.write(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} 展开
import java.io.*;
import java.util.Scanner;
public class ex {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
System.out.println("请输入");
String s = cin.next();
byte[] b = s.getBytes();
try {
FileOutputStream out = new FileOutputStream("ex.txt");
System.out.println("结果已打印");
out.write(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
} 展开
2个回答
展开全部
把 String s = cin.next();
改成 String s = cin.nextLine();
改成 String s = cin.nextLine();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询