لدي ملفين أحدهما لكتابة سجلين من البيانات من نوع formatted file data
والاخر لقراءة السجلين الذين تم كتابتهما في الملف الأول
هذا كود ملف القراءة
عند التنفيذ يظهر لي رسالة الاكسبشن
File not found
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class MailOrderRead {
public static void main(String[] args) {
int x = 0,x2,y = 0,y2 = 0;
try {
DataInputStream read = new DataInputStream(new FileInputStream(new File("c:\\test\\mailOrder.txt").getName()));
DataInputStream read2 = new DataInputStream(new FileInputStream(new File("c:\\test\\mailOrder2.txt").getName()));
System.out.println("Item number\t Quantity");
for (int i = 0; i < 2; i++) {
x = read.readInt();
x2 = read.readInt();
if(i == 1)
{
y = read2.readInt();
y2 = read2.readInt();
}
System.out.println(x + "\t" + x + "\n" + y + "\t" + y2);
}
read.close();
read2.close();
}catch (FileNotFoundException ex) {
System.out.println("File not found");
} catch (IOException ex) {
System.out.println("problem found while reading that file.");
}
}
}ساعدونا في تصحيح الكود؟
===================
وهذا الكود عن IOException
لا يعمل بشكل صحيح
import java.io.IOException;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
System.out.println("Enter id number");
try {
int id = sc.nextInt();
} catch (IOException e) {
System.out.println("not valid");
}
}
}تحياتي
