校验文件格式,读取File或MultipartFile文本文件中的每一行数据

		// 校验文件格式
        String originalFileName = file.getOriginalFilename();
        String fileType = originalFileName.substring(Objects.requireNonNull(originalFileName).lastIndexOf("."));
        if (!".txt".equals(fileType)) {
            return JsonData.buildResult(BizCodeEnum.MAINBOARD_IMEI_FILE_FORMAT_ERROR);
        }
        // 读取每行数据到List 1.MultipartFile 2.File
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(file.getInputStream()));
        //BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
        String imeiTxt;
        List<String> imeiList = new ArrayList<>();
        while ((imeiTxt = bufferedReader.readLine()) != null) {
            imeiList.add(imeiTxt);
        }

你可能感兴趣的:(收集,重难点收集,java)