| | |
| | | /** |
| | | * 替换文件中的某一行 |
| | | * @param ins 输入流 |
| | | * @param repalceWith 替换后的文本 |
| | | * @param replaceWith 替换的文本 |
| | | * @param lineIndex 行索引 0 based |
| | | */ |
| | | public static InputStream replaceAtLine(InputStream ins, int lineIndex,String repalceWith) throws IOException { |
| | | public static InputStream replaceAtLine(InputStream ins, int lineIndex,String replaceWith) throws IOException { |
| | | byte[] bytes = ins.readAllBytes(); |
| | | ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes); |
| | | Charset charset = Charsets.charset(detectFromInputStream(byteStream)); |
| | |
| | | while ((line = reader.readLine()) != null) { |
| | | // 如果是目标行,写入新内容 |
| | | if (currentLine == lineIndex) { |
| | | writer.write(repalceWith); |
| | | writer.write(replaceWith); |
| | | } else { |
| | | writer.write(line); |
| | | } |