절대 경로에서 파일을 읽어드리는 것
@Test
public void uploadTest() {
File file = new File("C:\\downloads\\test.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufReader = new BufferedReader(filereader);
String readLine = null;
try {
while((readLine = bufReader.readLine()) != null) {
System.out.println(line);
}
if ( fileReader != null ) {
fileReader.close();
}
if ( bufReader != null ) {
bufReader.close();
}
}
}
업로드를 통해 일회성으로 읽어드리는 것
@Controller
public class TestController {
public uploadTest(MultipartHttpServletRequest mRequest){
TestClass testClass = new TestClass();
testClass.testMethod(mRequest.getFile("[input type="file의 id]"));
}
}
public calss TestClass{
public void testMethod(MultipartFile multipartFile) {
BufferedReader bufReader = null;
String readLine = null;
try {
bufReader = new BufferedReader(new InputStreamReader(multipartFile.getInputStream()));
while ( readLine = bufReader.readLine() != null ) {
System.out.println( readLine );
}
if ( bufReader != null ) {
bufReader.close();
}
}
}
}