file.close() should be outside of while loop otherwise java.io.EOFException occur. You should place close() in finally. public void readFile() throws ClassNotFoundException { if (!dataFile.exists()) //생성한 파일이 존재하지 않으면 return return; ObjectInputStream in = null; //try 구문 바깥에 선언해줘서 다른 scope 에서도 사용가능하게 해준다! try { BufferedInputStream fileIn = new BufferedInputStream (new FileInputStream(dataFile)); ..
Error: could not find or load main class Main 이란 처음 보는 에러 발생 첫번째 삽질 Invalidate Caches / Restart 두번째 삽질 Edit Configurations... ... 그리고 이 외의 숱한 삽질 끝에 폴더 이름에 special character 인 '/'를 넣어서 안됐던 것,,, File I/O 라 생각없이 넣었던 것이 결국, 엄청난 시간낭비로,, 그래도 알아내서 다행 IntelliJ won't allow you to use the special character in the file path. Reference https://stackoverflow.com/questions/10654120/error-could-not-find-or-loa..
Reading and Writing Java Object to a file in java //Serialization 직렬화 - Object 자체를 file 에 저장하고 싶을 때 사용. 이 클래스를 상속하는 하위클래스들도 직렬화가 가능해진다. public class PhoneInfo implements Serializable { ... } public class PhoneManager { private final File dataFile = new File("PhoneBook.txt"); //create file ... public void storeFile(){ FileOutputStream file = null; try { file = new FileOutputStream(dataFile); try ..
for-each for (Type obj : Collection) {...} example for (CustomInfo c : customManagers) { System.out.println(c.toString()); } works only if the collection holds elements of type Type. public class Main{ public static void main(String[] args) { int[] arr = new int[]{ 1,2,3,4,5 }; //for-each. normally used for iterating Arrays or Collection for (int i : arr) { System.out.print(i); //12345 } System...
returning ArrayList from method Option 1 - Wrong //weight을 계산 그러나 과목별,학생별은 상관이 없는 상태. private MarkInfo getWeight() { int t_id = 0; int s_id = 0; double weight = 0; for (MarkInfo m : markInfos) { for (TestInfo t : testInfos) { if (t.getTestId() == m.getMarkId()) { t_id = m.getMarkId(); s_id = m.getMarkStudentId(); weight = m.getMark() * (t.getWeight() / 100); } } } return new MarkInfo(t_id, s_id,..
Collection framework 에는 ArrayList처럼 순차적으로 data를 저장시키는 컬렉션이 있는 반면, hashSet과 같이 데이터의 순서가 무시되는 컬렉션도 존재하기에 element를 알아내기 위해서는 Iterator method를 사용해야한다. hasNext() - return true. if there is element left inside the iteration next() - return next element previous() - return the previous element remove() - remove next element Example code Iterator itr = phoneInfo.iterator(); //iterate phoneInfo while (it..
- Total
- Today
- Yesterday
- Collection Framework
- Javascript Algorithm
- 프로그래머스 알고리즘
- rest parameter
- javascript
- C++
- math.max
- hackerrank javascript solution
- equals()
- spring boot application
- java
- HashMap
- 알고리즘
- algorithm
- Object type casting
- HackerRank Algorithm
- compareTo()
- 프로그래머스
- string class in java
- substring()
- easy algorithm
- code refactoring
- repeat()
- hackerrank
- hackerrank solution
- ... in Javascript
- hackerrank javascript
- 프로그래머스 알고리즘문제
- easy javascript algorithm
- math.abs
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |