1.简单加密&解密
1 package com.java7.myencrypt.main; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileNotFoundException; 6 import java.io.FileOutputStream; 7 import java.io.IOException; 8 9 public class MyEncrypt { 10 public static void main(String[] args) { 11 try { 12 File inFile = new File("inFile.txt"); 13 File outFile = new File("outFile.txt"); 14 15 if (inFile.createNewFile()) { 16 System.out.println("File is created!"); 17 } else { 18 System.out.println("File already exists."); 19 } 20 21 FileInputStream fis = new FileInputStream(inFile); 22 FileOutputStream fos = new FileOutputStream(outFile); 23 24 System.out.println(fis.available()); 25 int length = fis.available(); 26 for(int i = 0; i < length; i++) { 27 fos.write(fis.read()+100); 28 } 29 } catch (FileNotFoundException e) { 30 // TODO Auto-generated catch block 31 e.printStackTrace(); 32 } catch (IOException e) { 33 // TODO Auto-generated catch block 34 e.printStackTrace(); 35 } 36 } 37 }
1 package com.java7.mydecrypt.main; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileNotFoundException; 6 //import java.io.FileOutputStream; 7 import java.io.IOException; 8 9 public class MyDecrypt { 10 public static void main(String[] args) { 11 try { 12 File dcFile = new File("outFile.txt"); 13 // File dcNewFile = new File("dcNewFile.txt"); 14 15 if(dcFile.exists()) { 16 System.out.println("File already exists."); 17 } else { 18 System.out.println("File not found."); 19 } 20 // if(dcNewFile.createNewFile()){ 21 // System.out.println("File is created!"); 22 // } else { 23 // System.out.println("File already exists."); 24 // } 25 26 FileInputStream fis = new FileInputStream(dcFile); 27 // FileOutputStream fos = new FileOutputStream(dcNewFile); 28 29 System.out.println(fis.available()); 30 int length = fis.available(); 31 for(int i = 0; i < length; i++) { 32 System.out.print((char)(fis.read()-100)); 33 // fos.write((fis.read()-100)); 34 } 35 } catch (FileNotFoundException e) { 36 // TODO Auto-generated catch block 37 e.printStackTrace(); 38 } catch (IOException e) { 39 // TODO Auto-generated catch block 40 e.printStackTrace(); 41 } 42 } 43 }
时间: 2024-10-24 08:54:44