arrays - Java-Write in file -
i want name, last name , spacial code user, , save in 1 array, after write file. code doesn't have compiler error doesn't work.
public class writefile { public static void main(string[] args){ try { string array[][] = new string[100][2]; (int = 0; < array.length; i++) { randomaccessfile raf=new randomaccessfile("d://employee.txt","rw"); string inputname=joptionpane.showinputdialog("please insert first name"); array[i][0]=inputname; string inputlname=joptionpane.showinputdialog("please insert last name"); array[i][1]=inputlname; string inputmeliic=joptionpane.showinputdialog("please insert melii code"); array[i][2]=inputmeliic; raf.writeutf(array[i][0]); raf.writeutf(array[i][1]) ; raf.writeutf(array[i][1]); } } catch (filenotfoundexception e) { e.printstacktrace(); //to change body of catch statement use file | settings | file templates. } catch (ioexception e) { e.printstacktrace(); //to change body of catch statement use file | settings | file templates. } }
ok can modified code:
public static void main(string[] args){ randomaccessfile raf = null; try { string array[][] = new string[2][3]; raf=new randomaccessfile("d:\\employee.txt","rw"); (int = 0; < array.length; i++) { string inputname=joptionpane.showinputdialog("please insert first name"); array[i][0]=inputname; string inputlname=joptionpane.showinputdialog("please insert last name"); array[i][1]=inputlname; string inputmeliic=joptionpane.showinputdialog("please insert melii code"); array[i][2]=inputmeliic; raf.writechars(array[i][0]); raf.writechar(':'); raf.writechars(array[i][1]) ; raf.writechar(':'); raf.writechars(array[i][2]); raf.writechars("\n"); } raf.seek(0); string str = raf.readline(); while(str != null ){ system.out.println(str); string arr[] = str.split(":"); system.out.println(arrays.aslist(arr)); str = raf.readline(); } raf.close(); } catch (filenotfoundexception e) { try { raf.close(); } catch (ioexception ex) { logger.getlogger(ideone.class.getname()).log(level.severe, null, ex); } e.printstacktrace(); //to change body of catch statement use file | settings | file templates. } catch (ioexception e) { try { raf.close(); } catch (ioexception ex) { logger.getlogger(ideone.class.getname()).log(level.severe, null, ex); } e.printstacktrace(); //to change body of catch statement use file | settings | file templates. } }
Comments
Post a Comment