[Java的]进入, 在Java中做 – 输入, 在Java中输出
一个简单的入口和出口从键盘中的Java与扫描仪
import java.io.IOException;
import java.util.*; //thu vien dung lop Scanner
class java_in_out_put
{
public static void main(String agrv[]) throws IOException
{
String s;
int age;
Double M;
Scanner inp = new Scanner(System.in); //tao doi tuong inp thuoc lop Scanner
System.out.print("Insert your name : "); //Lenh in ra man hinh
s = inp.nextLine(); //nhap chuoi
System.out.print("Insert your age: ");
age = inp.nextInt(); //nhap so nguyen
System.out.println("Insert your Math: ");
M = inp.nextDouble();
System.out.printf("My name is %s , I %d yaers old and I am %.2f math scoren", s, age, M);
inp.close();
}
}
接着,在输出文件. 在这个项目中,我会从文件中读取包括行INPUT.TXT, 每一行具有名称, 年龄, 工资由逗号分隔, 然后写上OUTPUT.TXT不同行的文件信息:
首席执行官:
INPUT.TXT文件内容
阮文Q,21,100000.0
阮氏乙,20,200000.0
写入到output.txt文件将被
阮文Q
21
100000.0
阮氏乙
20
200000.0
import java.io.*;
import java.util.*;
class input_file
{
String ten[] = new String[100];
int tuoi[] = new int[100];
double luong[] = new double[100];
int i=0;
void read() throws IOException //phuong thuc doc tu file
{
String line[] = new String[100];
FileInputStream f = new FileInputStream("input.txt"); //tao bien tep f
Scanner input = new Scanner(f,"UTF-8"); //doc tu tep f su dung Scanner
while(input.hasNextLine()) //trong khi chưa het file
{
line[i]= input.nextLine(); //doc 1 dong
if(line[i].trim()!="") //neu dong khong phai rong
{
String item[] = line[i].split(","); //cat cac thong tin cua line bang dau phay
ten[i] = item[0];
tuoi[i] = Integer.parseInt(item[1]); //chuyen strin sang int
luong[i] = Double.parseDouble(item[2]);
}
i++;
}
input.close();
}
void write() throws IOException //phuong thuc ghi vao file
{
FileOutputStream f = new FileOutputStream("output.txt");
PrintWriter output = new PrintWriter(f);
int j=0;
while(j<i)
{
output.println(ten[j]);
output.println(tuoi[j]);
output.println(luong[j]);
j++;
}
output.close();
}
}
class java_in_out_file
{
public static void main(String []agr) throws IOException
{
input_file file = new input_file();
file.read();
file.write();
}
}



亲爱的 , cho e hỏi là viết hàm nhập va xuất 1 mảng số như thế nào ạ.e cảm ơn a nhiều:)))
Bạn dùng vòng lặp for để nhập nhé
亲爱的, cho e hỏi throws Exception với throws IOException khác nhau chỗ nào vậy a? 同 2 cái đó dùng để làm gì? tks a nhiều 🙂
Exception là ngoại lệ chyng của mọi ngoại lệ. 对进出口异常IOException异常.
我哥哥问我
例如,输入文件名, 年龄, 身份证号码, 我只是想单纯的身份证交纳出口输出文件名是怎样一个
希望你尽快回复
谢谢
那么,什么部分,你只写文件,写你想要什么.
Mình không hiểu, cùng là vào ra file nhưng Scanner/Prinwriter và FileInpuStream/FileOuputStream khác nhau như nào. 我在使用中看到 2 什么都OK.
UA, 符合它的错误 23, 24 “NumberFormatException的” 一个军事亲爱的
因此可以肯定,你的文件不知何故, 它肯定不读旧闻不会被读取,陈德良. 你看输入文件NHE.
Ë没关系订正一个=)))
˚F固定则a =))
如果你想留在输入空间再怎么说,他?
即输入: 阮文Ç, 20, 100000 仍然打印输出代码
您可以根据想要的东西是要分裂.
Ë想进入从电子文件中的一个整数数组复制
他们像往常一样, 不仅通过从文件中读取你.
E在java的平均先生问包 ,如果用户已经星级ķķ先生
你可以参考这里,等: https://nguyenvanhieu.vn/package-trong-java/
星冗长E请参阅的Java VS麻烦比(C V) ?? :((
长,但明确, 慢慢你就会熟悉.