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

Upload picture to server
Beginner Java- Why won't this compile? [closed]
keep reading input while program runs
Spring security and #Configuration order
How do I decide how many bytes to read from an inputstream?
best practice invoking webservices
Which data type to use in java?
Without Recursion giving memory error
SimpleDB: I can't put more than 100 items in a domain
Facebook 'code' parameter as part of query string for OAuth authentication
How to Display data from Database in JDBC -Java [duplicate]
Use an instance inside an anonymous class
a simple code, what is result of return?
android speech recognition service null pointer exceptions
syntax for java list interface used by hibernate in java?
unmarshalling XML with multiple namespaces

Categories

HOME
openlayers
zeromq
nullpointerexception
angular-material
at-command
sql-server-2016
ezpublish
modelica
nstableview
etl
alignment
static-libraries
hapi
seaborn
footer
predix
amazonsellercentral
cultureinfo
opennlp
buildbot
apache-commons-io
poltergeist
windows-server-2000
oracle-fusion-middleware
uiswipegesturerecognizer
amazon-kinesis-kpl
mpmediaquery
ios5
withings
uft-api
android-fingerprint-api
avro4s
ibpy
websphere-mq-fte
jquery-nestable
logparser
python-webbrowser
jlink
sage-one
veracode
jxcore
slickedit
django-scheduler
topbeat
url-pattern
bonobo
trash
merge-conflict-resolution
bstr
photobucket
freedesktop.org
intel-fortran
python-3.2
purge
0xdbe
method-parameters
cisco-ios
unity5.2.3
facebook-graph-api-v2.4
id3v2
project-planning
navigationservice
hyprlinkr
app42
mysqltuner
ms-project-server-2010
coderush
gnustep
coercion
yui-datatable
.nettiers
forums
mtj
django-notification

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