메뉴 건너뛰기

조회 수 7385 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

//파일을 읽고 쓰기 기능을 이용하여 일반문서를 읽고 암호화 하여
//저장하고 암호화된 문서를 읽고 일반 문서로 변환하는 프로그램 작성하기


 

import java.io.*;
import java.util.*;
 
class soo{
 public static void main(String[] args) throws IOException{
    System.out.println("1번과 2번중 하나를 눌러주세요 1번:파일을 읽고 암호화 합니다. " +
               " 2번:암호화 문서읽고 일반으로 변화합니다." );
    System.out.print(":");
    Scanner scan=new Scanner(System.in);
    int input=scan.nextInt();          //번호 입력할수있다.
  
    FileReader fr=null;
    FileWriter fw=null;
    int secret=3;   // 암호화&복호화 해주려는 값
   
   try{   
      if(input==1){                            //1번 입력  
      System.out.println("일반문서중 불러오고자 하는 문서명을 입력해주세요.ex)test.txt  ");
      System.out.print(":");
      String fileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력 
      fr=new FileReader(fileName);                       //불러온 파일에서 내용읽어온다.
    
     
      System.out.println("암호화된 파일을 저장할  .txt 명을 입력해주세요. ex)sos.txt");
      System.out.print(":");
      String encryptionFileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력
      fw=new FileWriter(encryptionFileName);        //암호화될 파일을 만든다.
     
      int data=0;
     
     while((data=fr.read())!=-1){
       data+=secret;   //암호화
       char ch=(char)data;  
       System.out.print(ch);         //암호화 출력    
       fw.write(data);  //암호화된 데이터를 저장한다.        
     }//while
    } //if
     
    else if(input==2){
     System.out.println("암호화 문서만 불러오세요 .ex)sos.txt  ");
     System.out.print(":");
     String fileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력 
     fr=new FileReader(fileName);              //복호화 문서 파일 내용을 읽어온다.
    
     System.out.println("복호화될 파일을 저장할  .txt 명을 입력해주세요. ex)sos.txt");
      System.out.print(":");
      String encryptionFileName=new Scanner(System.in).nextLine();  //불러오고자 하는파일명 입력
      fw=new FileWriter(encryptionFileName);        //복호화될 파일을 만든다.
     
     int data=0;
     while((data=fr.read())!=-1){
      data-=secret;   //복호화
      char ch=(char)data;  
      System.out.print(ch);         //복호화 출력
      fw.write(data);  //복호화된 데이터를 저장한다.
     
     }//while  
      }  //else if  
   }//try{}
   catch(FileNotFoundException abc){
       System.out.println("파일을 찾을수 없습니다.");
      }
   catch(IOException ee){
  System.out.println("파일 읽을수 없다.");
   }
      finally{
    try{
        fr.close();
        fw.close();  //저장값을 반환해준다.
       }
    catch(Exception ee){}
 
   
       }//finally 닫고
      
 } //main()
 
}  //class


List of Articles
번호 제목 날짜 조회 수
111 A java Runtime Environment(JRE) or Java Development Kit(JDK) must be ~~~~ 하면서 이클립스가 실행안될때. file 2019.03.05 789
110 변환 (문자, 숫자, KSC5601.....) 2019.01.16 1281
109 기본적인 스크립트 보안 2019.01.16 6044
108 JAVA/JSP SQL Injection 해킹 방지를 위한 코딩 2019.01.10 846
107 Java : JSOUP 를 이용, html에서 소스, 링크경로 추출후 절대 경로로 바꾸기 2019.01.08 1166
106 Apache Commons HttpClient 3.x 로 Http 서버에 파일 전송하기 file 2019.01.08 1136
105 JSON 문자열을 Map 으로 변환하기(Jackson 사용) 2019.01.08 1010
104 시간관련 클래스 file 2018.09.21 1186
103 직렬화 / 역직렬화 file 2018.09.21 951
102 예외처리 / 예외발생 file 2018.09.21 934
101 JAVA 현재 시간 구하기 file 2018.07.09 1266
100 JAVA 이클립스 인코딩 변경하기 file 2018.07.09 1587
99 JAVA JDK 제거하기 file 2018.07.09 1409
98 JAVA CentOS JDK 설치 및 환경변수 설정 file 2018.07.09 1821
97 JAVA 정규표현식을 이용한 패턴매칭(HTML 제거) 2018.07.09 1164
96 JAVA 두개의 문서 파일 비교하기 2018.07.09 2388
95 JAVA 인코딩을 변경하여 파일 출력하기 (EUC_KR) 2018.07.09 1105
94 JAVA TreeMap 인덱스 값 가져오기 및 Collections.sort 사용하기 2018.07.09 1486
93 JAVA public, private, protected 정리 2018.07.09 1001
92 JAVA HashMap의 Key값 출력하기 2018.07.09 1069
Board Pagination Prev 1 2 3 4 5 6 7 8 Next
/ 8

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved