public class UserDAOImplFile implements UserDAO { @Override public boolean insert(User user) { ObjectOutputStream out = null; try { ArrayListuserList = selectUserList(); userList.add(user); out = new ObjectOutputStream(new FileOutputStream("user.dat")); out.writeObject(userList); } catch (IOException e) { e.printStackTrace(); } finally { try { if (out != null) out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return false; } @Override public ArrayList selectUserList() { ObjectInputStream in = null; try { File f = new File("user.dat"); if (f.exists()) { try { in = new ObjectInputStream(new FileInputStream("user.dat")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { return (ArrayList ) in.readObject(); } catch (ClassNotFoundException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { return new ArrayList (); } } finally { try { if (in != null) in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return null; } }//버그임
'소프트웨어 개발 > Java - Basic' 카테고리의 다른 글
eclipse perspective이상해져서 지저분할때 (0) | 2014.09.17 |
---|---|
Eclipse TEXT파일 모조리 UTF-8 인코딩으로 만들기 (0) | 2014.09.17 |
Java에서 header붙이는 방법.. (0) | 2014.05.26 |
Jsoup 이용해서 쉽게 html 파싱하기 (0) | 2014.05.20 |
자바(Java)에서 HTML파일 읽어오기 예제 (0) | 2014.05.11 |