怎么读取java文件,Java怎么读取文件
當前位置:我的異常網? J2SE???Java怎么讀取文件
Java怎么讀取文件
www.myexceptions.net??網友分享于:2013-12-20??瀏覽:60次
Java如何讀取文件?
源文件如下,小弟沒有學過Java,下面是一段JAVA用RSA加密字符串的程序,
命令行的形式是Java ? PublicExample ? ABCDEFG
哪位大哥能把它改成,讀取一個公鑰,加密一個txt文件,并指定輸出私鑰路徑,及加密后txt的路徑
如命令行的形式是Java ? PublicExample ? c:\未加密.txt ? c:\公鑰.txt ? c:\生成私鑰.txt ? c:\生成加密.txt
/*
Public ? Key ? cryptography ? using ? the ? RSA ? algorithm.
*/
import ? java.security.*;
import ? javax.crypto.*;
import ? org.bouncycastle.jce.provider.JCERSACipher;
import ? java.io.*;
import ? java.io.FileReader;
import ? java.io.File;
import ? java.io.FileWriter;
public ? class ? PublicExample ? {
public ? static ? void ? main ? (String[] ? args) ? throws ? Exception ? {
//
// ? Check ? args ? and ? get ? plaintext
if ? (args.length ? !=1) ? {
System.err.println( "Usage: ? java ? PublicExample ? text ");
System.exit(1);
}
byte[] ? plainText ? = ? args[0].getBytes( "UTF8 ");
//
// ? Generate ? an ? RSA ? key
System.out.println( ? "\nStart ? generating ? RSA ? key " ? );
KeyPairGenerator ? keyGen ? = ? KeyPairGenerator.getInstance( "RSA ", ? new ? org.bouncycastle.jce.provider.BouncyCastleProvider());
keyGen.initialize(1024);
KeyPair ? key ? = ? keyGen.generateKeyPair();
System.out.println( ? "Finish ? generating ? RSA ? key " ? );
//
// ? Creates ? an ? RSA ? Cipher ? object ? (specifying ? the ? algorithm, ? mode, ? and ? padding).
//Cipher ? cipher ? = ? Cipher.getInstance( "RSA/ECB/PKCS1Padding ");
Cipher ? cipher ? = ? Cipher.getInstance( "RSA ", ? new ? org.bouncycastle.jce.provider.BouncyCastleProvider());
//
// ? Print ? the ? provider ? information
System.out.println( ? "\n " ? + ? cipher.getProvider().getInfo() ? );
System.out.println( ? "\nStart ? encryption " ? );
//
// ? Initializes ? the ? Cipher ? object.
文章評論
總結
以上是生活随笔為你收集整理的怎么读取java文件,Java怎么读取文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gprs 神奇宝典java,2016联通
- 下一篇: 泛型java博客园,Java深度历险之J