Time:09-23
CodePudding user response:
how remote code is applied to implement the external file encryption external files
Quote: refer to the original poster weixin_44165171 response: how remote code is applied to implement the external file encryption external files Define your own & lt;/span>; import java.io.File; Import the Java. IO. RandomAccessFile; import java.util.Scanner; Public class Test1 {Public static void main (String [] args) {System. The out. Println (" input file path: "); String s=new Scanner (System.) in nextLine (); The File f=new File (s); if(! F.i sFile ()) {System. The out. Println (" please enter the correct path to the file "); return ; } System. The out. Println (" KEY: "); Int key=new Scanner (System.) in nextInt (); Try {Encrypt (f, key); System. The out. Println (" encryption/decryption complete "); } the catch (Exception e) {System. The out. Println (" encryption/decryption failure "); e.printStackTrace(); } } Private static void encrypt (File f, int key) throws the Exception {/* * 1. New RandomAccessFile object is assigned to the raf * 2. Single byte read cycle, read the byte value is assigned to b * 3. B or different key, the result in the assigned to b * 4. Locate the subscript seek back to the previous position (raf) getFilePointer () - 1) * 5. The byte value b written back to the file * 6. Close the raf This can't use?
Page link:https//www.codepudding.com/Mobile/24376.html