package com.guoyun.bean;
import java.lang.annotation.Target;
/**
* ClassName:
* Function: ADD FUNCTION
* Reason: ADD REASON
*
* @author
* @Date
* @since Ver 1.1
*/
public class SecretCode {
private int[] content=new int[20];
private int pswkey;
public SecretCode(int[] content, int pswkey) {
this.content = content;
this.pswkey = pswkey;
}
public void show(){
System.out.println("解析后的密码为:");
for (int i = 0; i <content.length ; i++) {
if(content[i]!=0){
System.out.println((char) (content[i] - pswkey));
}
System.out.println();
}
}
public int[] responed(){
int[] temp=new int[20];
String content="ok,copythat!";
char[] chars=content.toCharArray();
for (int i = 0; i < chars.length; i++) {
temp[i]=chars[i]+pswkey ;
}
return temp;
}
}
********************************************************************
package com.guoyun.utils;
import com.guoyun.bean.SecretCode;
import java.io.*;
/**
* ClassName:
* Function: ADD FUNCTION
* Reason: ADD REASON
*
* @author
* @Date
* @since Ver 1.1
*/
public class FileUtils {
SecretCode secretCode;
public void readCode(){
BufferedReader reader=null;
String temp="";
try {
reader=new BufferedReader(new FileReader("E:/JAVA/新建文件夹/code.txt"));
while ((temp=reader.readLine())!=null){
String[] s = temp.split(" ");
int[] arr=new int[20];
for (int i = 0; i <s.length ; i++) {
arr[i]=Integer.parseInt(s[i]);
}
secretCode=new SecretCode(arr,8);
secretCode.show();
}
} catch (Exception e) {
System.out.println(e.getStackTrace());
}finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void writeCode(){
BufferedWriter writer=null;
try {
writer=new BufferedWriter(new FileWriter("E:/JAVA/新建文件夹/code.txt",true));
int[] arr=secretCode.responed();
writer.newLine();
for (int i = 0; i <arr.length ; i++) {
writer.write(arr[i]+" ");
}
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
*****************************************************************************
package com.guoyun.view;
import com.guoyun.utils.FileUtils;
/**
* ClassName:
* Function: ADD FUNCTION
* Reason: ADD REASON
*
* @author
* @Date
* @since Ver 1.1
*/
public class MainView {
public static void main(String[] args) {
FileUtils fileUtils=new FileUtils();
fileUtils.readCode();
fileUtils.writeCode();
}
}
原文:https://www.cnblogs.com/aojie/p/12386865.html