| 12 | import java.util.List; |
| 13 | |
| 14 | @Slf4j |
| 15 | public class AddTableField { |
| 16 | |
| 17 | /** |
| 18 | * 一次性读取全部文件数据 |
| 19 | * @param strFile |
| 20 | */ |
| 21 | public static void readFile(String strFile) { |
| 22 | try { |
| 23 | InputStream is = new FileInputStream(strFile); |
| 24 | int iAvail = is.available(); |
| 25 | byte[] bytes = new byte[iAvail]; |
| 26 | is.read(bytes); |
| 27 | log.info("文件内容:\n" + new String(bytes)); |
| 28 | is.close(); |
| 29 | } catch (Exception e) { |
| 30 | e.printStackTrace(); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * 按行读取文件 |
| 36 | * @param strFile |
| 37 | */ |
| 38 | public static List<String> readFileByLine(String strFile) { |
| 39 | List<String> strList = new ArrayList<>(); |
| 40 | try { |
| 41 | File file = new File(strFile); |
| 42 | BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); |
| 43 | String strLine = null; |
| 44 | int lineCount = 1; |
| 45 | while (null != (strLine = bufferedReader.readLine())) { |
| 46 | strList.add(strLine); |
| 47 | // log.info("第[" + lineCount + "]行数据:[" + strLine + "]"); |
| 48 | // System.out.println("第[" + lineCount + "]行数据:[" + strLine + "]"); |
| 49 | lineCount++; |
| 50 | } |
| 51 | } catch (Exception e) { |
| 52 | e.printStackTrace(); |
| 53 | } |
| 54 | return strList; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * 按行读取全部文件数据 |
| 59 | * |
| 60 | * @param strFile |
| 61 | */ |
| 62 | public static StringBuffer readFileAll(String strFile) throws IOException { |
| 63 | StringBuffer strSb = new StringBuffer(); |
| 64 | InputStreamReader inStrR = new InputStreamReader(new FileInputStream(strFile), "UTF-8"); |
| 65 | // character streams |
| 66 | BufferedReader br = new BufferedReader(inStrR); |
| 67 | String line = br.readLine(); |
| 68 | while (line != null) { |
| 69 | strSb.append(line).append("\r\n"); |
| 70 | line = br.readLine(); |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected