Does a file have to be updated in some way for Java? -
So I start with a text file; In the beginning, the number 3 (winning zodiac) in this text file is 3 Wenningen. I can read them without errors, with a scanner I can add voning without errors, if any voning is added then the number above the file has increased by 1.
The problem is as follows: If any voning has been added, the file has changed. The number is now 4, and a voning has been added. However, if I want to read all Vaughan, then Java gives exception to the 4th voning. So for some reason I can not read the fourth voning.
What could be the reason? Do I have to save the file in some way after the file has changed?
Help is greatly appreciated!)!
Edit
Note: The Dutch word for the voning house is the code to read the file:
read public static PortFill (String Infil) {Try {scanner sc = new scanner (new file (infil)); ArrayList & LT; Woning & gt; Wlijst = New Arrestist & Lt; Woning & gt; (); Portiftville P = new portiff (); Int woningen = sc.nextInt (); Int i = 0; While (i & lt; winning) {sc.nextLine (); String tag = sc.nextLine (); Wlijst.add (Woning.read (SC)); Wlijst.get (i) .setTag (tag); //System.out.println (wlijst.get (i) .getTag ()); //System.out.println (wlijst.toString ()); P.voegToe (wlijst.get (i)); I ++; } Sc.close (); Return p; } Hold (exception e) {System.out.println ("Portefeuille: exception is caught"); Portiftville P = new portiff (); Return p; }} The code to write the file:
Public static zero instrument file (Portable port, int winning) {try (print out outer = new printrover (New buffed vaitters (new flamer ("McLar.Text", false)))} {winning = winning + 1; Out.println (woningen); ArrayList & LT; Woning & gt; Wlijst = New Arrestist & Lt; Woning & gt; (); Wlijst = port.woninglijst; For (int i = 0; i & lt; wlijst.size (); i ++) {if (wn) welding of the installation) (KoopWoning kw = (KoopWoning) wlijst.get (i); KoopWoning.writeToFileK (kw, outside); } And {hurunging hw = (hoernewing) wlijst.get (i); Hoorvouning Writingfile h (hw, out); }} Out.close (); } Hold (exception e) {System.out.println (e.getMessage ()); System.out.println ("writeoffofile: exceptions were caught"); }} The file is showing as follows:
3 TE Compensation: Emmalaan 23 3051 Jesse Rotterdam 7 Cameron Coppell's 300000 Engerfire C Vercot: Emmalan 25 3051JC Rotterdam 5 kamers Vraagprijs 280000 Energiepeil A To Hur: Javstyat 88 4078 KB Eindhoven 3-Camera Hurrridge 500 I do not know what the winner is, but as far as I know, close the file after adding the file and then try to read the data in the file. This definition has always been stuck in my mind that after you finish your process, the file should be closed. I can only guess that you have done two Java classes for reading and writing or writing and reading methods of the same class. Provide some code after that so that everyone is asking you all about it.
Comments
Post a Comment