Java Path File Write nio writeLineS(String filePath, String msg, int line)

Here you can find the source of writeLineS(String filePath, String msg, int line)

Description

Write data to a specific line of a text file.

License

LGPL

Declaration

public static void writeLineS(String filePath, String msg, int line) throws IOException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.File;

import java.io.IOException;

import java.nio.file.Files;

import java.util.List;

public class Main {
    /**// ww w.j  a  va2s.  c  o  m
     * Write data to a specific line of a text file. <br>
     * Will override the old data.
     */
    public static void writeLineS(String filePath, String msg, int line) throws IOException {
        File f = new File(filePath);
        List<String> lines = Files.readAllLines(f.toPath());
        lines.set(line - 1, msg);
        Files.write(f.toPath(), lines);
    }
}

Related

  1. writeFully(Path filePath, byte[] bytes)
  2. writeJaasConfig(File krbDir, String princ, String keytabPath)
  3. writeJson(Object data, Path path)
  4. writeLastReadDate(String sinceDate, Path sinceFile)
  5. writeLines(Path path, T... a)
  6. writeOrAppendLinesToFile(boolean append, Path filePath, String... lines)
  7. writeOutputToFile(Path path)
  8. writeString(Path path, String str)
  9. writeString(String path, String data)