شكرا لكم
سأجرب الطريقتين لأن المشكلة لم تحل الى الان
شكرا لكم
سأجرب الطريقتين لأن المشكلة لم تحل الى الان
السلام عليكم
لم اجرب ما اقترحته اخ ابو مازن فهل انت جربت ان تضيف إلى ملف append واستطعت قراءة البيانات التي اضفتها للملف بشكل سليم دون رمي الاستثناء CorruptedFileException باستعمال الطريقة التي اقترحتها
نعم...
صفحاتي: صفحة حسام الملحم www.hussam.ws مدونة
آخر المشاريع: مشروع لغة برمجة عربية شيئية التوجه
ألعاب على الجوال : 1-(لعبة O X على الجوال ) 2-(لعبة الرقم السري على الجوال ) 3-(لعبة آخر حبة على الجوال )
ألعاب على الحاسب: لعبة الوزراء الثمان ، لعبة شطرنج ، لعبة التركيب Tetris
مواضيعي:
الفرق الجذري بين الجافا و C# شرح التعامل مع WTK لبرمجة الجوالات
مشاركاتي:
برنامج (كاتب) للكاتب فهد OMLX، برنامج (المحول) للكاتب فهد OMLX، برنامج (Unit Storm) للكاتب بشير C&Dell، أيهما أكبر الأعداد الصحيحة أم الطبيعية للكاتب Romanof، سؤال رياضي بحت للكاتب VB6-Rocket، التحدي الكبير للكاتب ANSI،
السلام عليكم
جربت طرقة الاخ ابو مازن وهذا هو كود الاضافة :
public void addRecord()
{
int studNumber = 0;
studrec record;
String fieldValues[] = userInterface.getFieldValues();
if ( ! (fieldValues[ userInterface.NAME ].equals( "" ) ) ){
// output values to file
try {
openFile(file);
studNumber = Integer.parseInt(fieldValues[ userInterface.ID ]);
if ( studNumber > 0 )
{
// create new record
record = new studrec(fieldValues[studenterUI.NAME],
studNumber,0);
// output record and flush buffer
output.writeObject( record );
output.flush();
closeFile();
}//if
else
{
JOptionPane.showMessageDialog( this,
"Student number must be greater than 0",
"Bad Student number", JOptionPane.ERROR_MESSAGE );
}
// clear textfields
userInterface.clearFields();
//closeFile();
} // end try
// process invalid account number or balance format
catch ( NumberFormatException formatException ) {
JOptionPane.showMessageDialog( this,
"Bad Student number ", "Invalid Number Format",
JOptionPane.ERROR_MESSAGE );
}
// process exceptions from file output
catch ( IOException ioException ) {
JOptionPane.showMessageDialog( this, "Error writing to file",
"IO Exception", JOptionPane.ERROR_MESSAGE );
System.out.println("closing file");
//closeFile();
}
}
}// end method addRecordوهذا كود القراءة :
public String[] readRecord()
{
studrec record=null;
// input the values from the file
try {
record = ( studrec ) input.readObject();
// create array of Strings to display in GUI
String values[] = { String.valueOf( record.getstudentid()),
record.getstudentname(),String.valueOf( record.getGrade())};
System.out.println(" Name =" + record.getstudentname());
fin.skip((long)4);
return values;
}
// display message when end-of-file reached
catch ( EOFException eofe ) {
//System.out.println("Error: "+record);
JOptionPane.showMessageDialog( this,
"End of file exception read" + eofe,
"EOFException", JOptionPane.ERROR_MESSAGE );
eofe.printStackTrace();
return null;
}
// display error message if class is not found
catch ( ClassNotFoundException cnfe ) {
System.out.println("Error: "+record);
JOptionPane.showMessageDialog( this,
"Unable to create object" + cnfe,
"ClassNotFoundException", JOptionPane.ERROR_MESSAGE );
cnfe.printStackTrace();
return null;
}
// display error message if cannot read due to problem with file
catch (IOException ioe ) {
System.out.println("Error: "+record);
JOptionPane.showMessageDialog( this,
"Error during read from file" + ioe,
"IOException", JOptionPane.ERROR_MESSAGE );
ioe.printStackTrace();
return null;
}
catch (Exception e ) {
System.out.println("Error: "+record);
JOptionPane.showMessageDialog( this,
"Error during read from file" + e,
"Exception", JOptionPane.ERROR_MESSAGE );
e.printStackTrace();
return null;
}
} // end method readRecordجزاكم الله خير
والبروجكت الان شارف على الانتهاء
طيب، لم تقل لنا هل نفعت الطريقة أم لا؟!
صفحاتي: صفحة حسام الملحم www.hussam.ws مدونة
آخر المشاريع: مشروع لغة برمجة عربية شيئية التوجه
ألعاب على الجوال : 1-(لعبة O X على الجوال ) 2-(لعبة الرقم السري على الجوال ) 3-(لعبة آخر حبة على الجوال )
ألعاب على الحاسب: لعبة الوزراء الثمان ، لعبة شطرنج ، لعبة التركيب Tetris
مواضيعي:
الفرق الجذري بين الجافا و C# شرح التعامل مع WTK لبرمجة الجوالات
مشاركاتي:
برنامج (كاتب) للكاتب فهد OMLX، برنامج (المحول) للكاتب فهد OMLX، برنامج (Unit Storm) للكاتب بشير C&Dell، أيهما أكبر الأعداد الصحيحة أم الطبيعية للكاتب Romanof، سؤال رياضي بحت للكاتب VB6-Rocket، التحدي الكبير للكاتب ANSI،
هذا الموضوع مغلق.
المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية
جارٍ التحقق من المتواجدين…