Refactor FileNotFoundException examples

This commit is contained in:
Grzegorz Piwowarek 2016-10-04 18:11:37 +02:00
parent 0dc8119722
commit f12e6ee2d0

View File

@ -1,14 +1,10 @@
package org.baeldung.core.exceptions; package org.baeldung.core.exceptions;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.junit.Test; import org.junit.Test;
import java.io.*;
public class FileNotFoundExceptionTest { public class FileNotFoundExceptionTest {
private static final Logger LOG = Logger.getLogger(FileNotFoundExceptionTest.class); private static final Logger LOG = Logger.getLogger(FileNotFoundExceptionTest.class);
@ -49,15 +45,14 @@ public class FileNotFoundExceptionTest {
} }
} }
protected void readFailingFile() throws IOException { private void readFailingFile() throws IOException {
BufferedReader rd = null; BufferedReader rd = new BufferedReader(new FileReader(new File(fileName)));
rd = new BufferedReader(new FileReader(new File(fileName)));
rd.readLine(); rd.readLine();
// no need to close file // no need to close file
} }
class BusinessException extends RuntimeException { private class BusinessException extends RuntimeException {
public BusinessException(String string, FileNotFoundException ex) { BusinessException(String string, FileNotFoundException ex) {
super(string, ex); super(string, ex);
} }
} }