I'm trying to write the data from a picture I am encoding through Base64 to byte array then to the file that will be read by a plc program later on
This is meant to be used by a plc program later. (The plc is attached to a laser cutter.) I've tried to use FileOutputStream()
as a way to write the data which with my current method did not turn out too dandy.
public static void main(String[] args)throws Exception {
File file = new File("$PATH");
File outputFile = new File("$OutputFilePath");
String encodeString = encodeFile(file);
System.out.println(encodeString);
}
private static String encodeFile(File file) throws Exception{
FileInputStream fileReader = new FileInputStream(file);
byte[] bytes = new byte[(int)file.length()];
fileReader.read(bytes);
return new String(Base64.getEncoder().encode(bytes), "UTF-8");
}
The code above does not provide my current attempts of making my program work the intended way but I am lost as of now but i was hoping that you might be able to shed some light on what I should do to end up in the right direction.