首页 > 代码库 > 练习.加密和解密
练习.加密和解密
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 block31 e.printStackTrace();32 } catch (IOException e) {33 // TODO Auto-generated catch block34 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 block37 e.printStackTrace();38 } catch (IOException e) {39 // TODO Auto-generated catch block40 e.printStackTrace();41 }42 }43 }
练习.加密和解密
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。