Skip to content

Instantly share code, notes, and snippets.

@OmkarKirpan
Created September 14, 2022 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmkarKirpan/af066cbd01ca72ad3be6074a06b62dc0 to your computer and use it in GitHub Desktop.
Save OmkarKirpan/af066cbd01ca72ad3be6074a06b62dc0 to your computer and use it in GitHub Desktop.
store decoded binary file to path
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment