java


Read from file to arraylist of object, why I get IOException?


I write a method which saves my arraylist of clients to file. After that, at the beginning of my program I wanna read from file and get all clients to the arraylist. My problem is that program throws IOException and also these notes:
Note: test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
My code:
ArrayList<Client>accountList=new ArrayList<Client>();
File fileRead=new File("file.txt");
try{
FileInputStream arrayAccountsList=new FileInputStream(fileRead);
ObjectInputStream ois=new ObjectInputStream(arrayAccountsList);
accountList=(ArrayList<Client>)ois.readObject();
arrayAccountsList.close();
}
catch(FileNotFoundException e){
System.out.println("FileNotFoundException");
}
catch(IOException d){
System.out.println("IOEXCEPTION");
}
catch(ClassNotFoundException f){
System.out.println("ClassNotFoundException");
}
Can you tell me what I did wrong here? Much thanks.
EDIT:
stacktrace output:
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2624)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3099)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:853)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:349)
at Bank.main(Bank.java:23)
23 line is:
ObjectInputStream ois=new ObjectInputStream(arrayAccountsList);

Related Links

Applying blur using RenderScript in Android creates weird output
Convert regular date and time to Julian date and vice versa
Java NoClassDefFoundError, Not Sure What's Wrong
Not sure I am using inheritance/polymorphism issue?
Finding the Mode of Integers in an Array
How to configure embedded Tomcat integrated with Spring to listen requests to IP address, besides localhost?
Access Canvas From JFrame
For PBKDF2, using HMAC-SHA256 is more secure than using HMAC-SHA-1?
Get Value from XML string
How to get radio button's id and convert to string?
Hamcrest Matchers - Assert Type of List
how to sort List<Object[]>?
How to use GridBagLayout to make a JLabel 1 column wide and then a JTextField 2 columns wide (for a total width 3 columns)
How to get access to object
Java regex placing # in character classes
Is Model 1 a subcategory of the MVC architecture?

Categories

HOME
vim
proxy
gremlin
single-sign-on
tinymce
appx
lodash
relay
rdf
webpack-2
podio
paradox
synchronization
iggrid
gorm
nano-server
wheelnav.js
mapserver
django-simple-history
google-static-maps
invantive-sql
excel-vba-mac
karma-jasmine
visual-composer
physics-engine
tar
mustache.php
php-openssl
firebase-crash-reporting
compatibility
primitive
javascriptcore
iframe-resizer
galsim
geopositioning
android-ble
io-redirection
suricata
vxworks
retina-display
http-live-streaming
estimote
s
osx-mavericks
jlink
idisposable
arrow-keys
mediaelement
libpng
savon
thrust
plottable.js
markojs
hexdump
purge
sailfish-os
generic-programming
system32
proj4js
bigbluebutton
offloading
fpml
cctv
java-metro-framework
gulp-less
markers
datagridviewcolumn
prettify
farseer
web2py-modules
blending
easy-install
ocunit
factory-method
typoscript2
hamiltonian-cycle
funscript
errai
getmessage
dotnethighcharts
bigcouch
netdna-api
stage
zpt
substrings
brewmp
multiple-languages
.net-1.0
ajax-forms

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App