Skip to content

Instantly share code, notes, and snippets.

@OmkarKirpan
Created September 14, 2022 04:09
Show Gist options
  • Select an option

  • Save OmkarKirpan/af066cbd01ca72ad3be6074a06b62dc0 to your computer and use it in GitHub Desktop.

Select an option

Save OmkarKirpan/af066cbd01ca72ad3be6074a06b62dc0 to your computer and use it in GitHub Desktop.

Revisions

  1. OmkarKirpan created this gist Sep 14, 2022.
    33 changes: 33 additions & 0 deletions FilesReadFileExample.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    import java.nio.charset.StandardCharsets;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.util.Base64;
    import java.util.List;

    public class FilesReadFileExample {

    public static void main(String[] args) {

    Path path = Paths.get("infile.jks");
    Path outpath = Paths.get("outfile.jks");
    try {
    byte[] bs = Files.readAllBytes(path);
    // List<String> strings = Files.readAllLines(path, StandardCharsets.UTF_8);
    String plaintxt = new String(bs);
    System.out.println("Read bytes: \n"+new String(bs));
    System.out.println("Read lines: \n"+plaintxt);

    byte[] asBytes = Base64.getDecoder().decode(bs);
    // String base64Decoded = new String(asBytes, StandardCharsets.UTF_8);
    // System.out.println("Base64 decoded text: " + base64Decoded);


    Path writtenFilePath = Files.write(outpath, asBytes);
    System.out.println("writtenFilePath: \n"+writtenFilePath.toAbsolutePath());
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    }