1. Simple Encryption & Decryption
1 packageCom.java7.myencrypt.main; 2 3 ImportJava.io.File; 4 ImportJava.io.FileInputStream; 5 ImportJava.io.FileNotFoundException; 6 ImportJava.io.FileOutputStream; 7 ImportJava.io.IOException; 8 9 public classMyencrypt {Ten public static void Main (string[] args) {One-to-one try {inFile = new file ("InFile.txt" ); file OutFile = new file ("Outfil E.txt ""), If (Infile.createnewfile ()) {System.out.println ("File is created!" ), or else {System.out.println ("File already exists.") ) }20 fileinputstream fis = new FileInputStream (inFile), fileoutputstream fos = new Fileo Utputstream (outFile); System.out.println (Fis.available ()); int length = fis.available (); i = 0; i < length; i++ ) {fos.write (Fis.read () +100 ), }29} catch (FileNotFoundException e) {//TODO Auto-gene Rated Catch block31 e.printstacktrace (); catch (IOException e) {//TODO auto-generated catch block34 span> e.printstacktrace (); }36 }37} /span>
1 PackageCom.java7.mydecrypt.main;2 3 ImportJava.io.File;4 ImportJava.io.FileInputStream;5 Importjava.io.FileNotFoundException;6 //import Java.io.FileOutputStream;7 Importjava.io.IOException;8 9 Public classMydecrypt {Ten Public Static voidMain (string[] args) { One Try { AFile Dcfile =NewFile ("OutFile.txt"); - //file Dcnewfile = new file ("DcNewFile.txt"); - the if(Dcfile.exists ()) { -System.out.println ("File already exists.")); -}Else { -System.out.println ("File not found.")); + } - //if (Dcnewfile.createnewfile ()) { + //System.out.println ("File is created!"); A //} else { at //System.out.println ("File already exists."); - // } - -FileInputStream FIS =NewFileInputStream (dcfile); - //FileOutputStream fos = new FileOutputStream (dcnewfile); - in System.out.println (Fis.available ()); - intLength =fis.available (); to for(inti = 0; i < length; i++) { +System.out.print ((Char) (Fis.read ()-100)); - //Fos.write ((Fis.read () -100)); the } *}Catch(FileNotFoundException e) { $ //TODO auto-generated Catch blockPanax Notoginseng e.printstacktrace (); -}Catch(IOException e) { the //TODO auto-generated Catch block + e.printstacktrace (); A } the } +}
Practice. Encryption and decryption