当前位置: 代码迷 >> J2SE >> 帮忙用字节流改上、多谢
  详细解决方案

帮忙用字节流改上、多谢

热度:53   发布时间:2016-04-24 00:36:32.0
帮忙用字节流改下、谢谢
改为FileOutputStream和FileInputStream字节流怎么改,求指教。

Java code
import java.io.*;import java.awt.*;import java.awt.event.*;public class Example10_6{public static void main(String args[]){char a[]="今晚10点进攻".toCharArray();int n=0,m=0;try{File f=new File("secert.txt");for(int i=0;i<a.length;i++){a[i]=(char)(a[i]^'R');}FileWriter out=new FileWriter(f);out.write(a,0,a.length);out.close();FileReader in=new FileReader(f);char tom[]=new char[10];System.out.println("密文:");while((n=in.read(tom,0,10))!=-1){String s=new String(tom,0,n);System.out.print(s);}in.close();in=new FileReader(f);System.out.println("");System.out.println("明文");while((n=in.read(tom,0,10))!=-1){for(int i=0;i<n;i++){tom[i]=(char)(tom[i]^'R');}String s=new String (tom,0,n);System.out.print(s);}in.close();}catch(IOException e){System.out.println("File read Error");}}}


------解决方案--------------------
查查api吧
------解决方案--------------------
Java code
package com.design.test;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class test {    public static void main(String args[]) {        byte[] a="今晚10点进攻".getBytes();        //char a[] = "今晚10点进攻".toCharArray();        int n = 0, m = 0;        try {            File f = new File("D://secert.txt");            for (int i = 0; i < a.length; i++) {                a[i] =  (byte) (a[i] ^ 'R');            }            FileOutputStream out=new FileOutputStream(f);            //FileWriter out = new FileWriter(f);            out.write(a, 0, a.length);            out.close();            FileInputStream in=new FileInputStream(f);        //    FileReader in = new FileReader(f);            //char tom[] = new char[10];            byte tom[]=new byte[1024];            System.out.println("密文:");                        while ((n = in.read(tom, 0, 10)) != -1) {                String s = new String(tom, 0, n);                System.out.print(s);            }            in.close();            //in = new FileReader(f);            in=new FileInputStream(f);            System.out.println("");            System.out.println("明文");            while ((n = in.read(tom, 0, 10)) != -1) {                for (int i = 0; i < n; i++) {                    tom[i] = (byte) (tom[i] ^ 'R');                }                String s = new String(tom, 0, n);                System.out.print(s);            }            in.close();        }        catch (IOException e) {            System.out.println("File read Error");        }    }}
  相关解决方案