메뉴 건너뛰기

조회 수 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 자바 String Class 문자열 처리 함수에 대한 정리 2021.03.31 106
110 자바 Statement PreparedStatement 차이 알아보기 file 2023.02.15 53
109 자바 JXL 엑셀파일을 읽어 배열리턴 : JAVA EXCEL ArrayList 2016.12.09 4389
108 자바 int 값 자리수 구하기 file 2023.02.15 74
107 자바 extends, implements 차이점 알아보기 file 2023.02.15 75
106 자바 extends Thread, implements Runnable 차이 file 2023.02.15 77
105 자바 - 공백 문자 제거하기 (trim, replaceAll) file 2021.03.31 173
104 인터페이스와 다형성 2016.09.13 3535
103 인터페이스 2016.09.13 3089
102 익명클래스 2016.09.13 3143
101 이클립에서 Javadoc 생성시 unmappable character for encoding MS949 에러가 발생할때 file 2019.03.05 730
100 이클립에서 FTP 접속하면서 Operation failed. File system input or output error 가 날때 file 2019.03.05 878
99 이클립스에서 같은 파일을 여러 편집창으로 띄우기 file 2019.03.05 677
98 이클립스를 화려하게 꾸며보자 file 2016.09.19 4457
97 이클립스 플러그인 삭제방법 file 2016.09.19 4721
96 이클립스 html, js 등등의 파일에서 에러표시 지우기 2019.03.05 1447
95 웹브라우저(크롬) 설정하여 웹을 실행해 보자 file 2016.09.19 7205
94 원하는 패턴의 날짜 구하기 : JAVA 2016.12.09 3608
93 오토박싱 2016.09.13 3246
92 예외처리(Exception handling)방법 file 2016.09.21 4585
Board Pagination Prev 1 2 3 4 5 6 7 8 Next
/ 8

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

© k2s0o1d4e0s2i1g5n. All Rights Reserved