import java.io.*;
public class Test {
public static void main(String[] args) throws Exception {
File sourcefile = new File("Test.txt");
FileInputStream instream = new FileInputStream(sourcefile);
int length = (int) sourcefile.length();
byte[] sign = new byte[length];
instream.read(sign, 0, length);
instream.close();
for (int i = 0; i < sign.length; i++) {
System.out.print(sign[i]+",");
}
}
}
public class Test {
public static void main(String[] args) throws Exception {
File sourcefile = new File("Test.txt");
FileInputStream instream = new FileInputStream(sourcefile);
int length = (int) sourcefile.length();
byte[] sign = new byte[length];
instream.read(sign, 0, length);
instream.close();
for (int i = 0; i < sign.length; i++) {
System.out.print(sign[i]+",");
}
}
}
解决方案 »
- 比较郁闷,不知道问题出在什么地方
- 使用JDBC桥连接MySQL数据库,把 ”JDBC驱动的类包解压到JAVA应用程序的运行目录“怎么理解这句话,”JAVA应用程序的运行目录“什么意思,具体问题请看:
- awt里面怎么响应右键点击的事件?
- 关于解析网络xml的中文问题
- request.getsession()的方法问题?
- 这个题目好象编译有错啊>??再线等
- Swing Graphics 绘制图片问题
- 那儿可以下载把class转化为exe文件的jet下载,只是暂时用一下,急!
- 为什么运行结果是1234.请详细解答
- 1.1—Java这么流行,知道为什么嘛?!
- java中调用有界面的DLL(VC)的问题?
- PreparedStatement中的setArray(int i, Array x) 应该怎样使用???
InputStream in = new FileInputStream(new File(filename));
int byteCount;
if ( (byteCount = in.read(buffer)) == -1 ) {
//buffer is what you want
} else {
//buffer is not large enough
}
in.close();
我在IE的地址栏里输入:“http://community.csdn.net/Expert/topic/3286/3286010.xml?temp=.6665308”,可是显示的是下面的结果:秋秋 一级(初级) user1 100 3286010 关于输入流问题(在线等,来就有分)--如果再没人回复我这辈子是不来这个论坛了--太伤心了 838032 qiuqiu_luck Java J2SE / 基础类 1 2004-08-18 12:55:53 100 0 5401 0 我要从一个文件输入流中获得一个字节数组。也就是说把输入流中的数据全都读进一个字节数组中,我最后要的就是这种形式:byte[] sign;我要代码! 三星堆五级(中级)user5100232821163286010527122ntzls0import java.io.*; public class Test { public static void main(String[] args) throws Exception { File sourcefile = new File("Test.txt"); FileInputStream instream = new FileInputStream(sourcefile); int length = (int) sourcefile.length(); byte[] sign = new byte[length]; instream.read(sign, 0, length); instream.close(); for (int i = 0; i < sign.length; i++) { System.out.print(sign[i]+","); } } }2004-08-18 13:06:00
byte[] sign = new byte[length];
in.read(sign, 0, size);
in.close();
return sign;}
import java.security.*;
import java.io.*;
import javax.crypto.*;public class GengeratorPairsTest {
public static void main(String []args){
try {
if(args[0].equals("-genkeypairs")){
KeyPairGenerator keygen = KeyPairGenerator.getInstance("DSA");
SecureRandom random = new SecureRandom();
keygen.initialize(1024, random);
KeyPair keypairs = keygen.generateKeyPair();
PublicKey pubKey = keypairs.getPublic();
PrivateKey priKey = keypairs.getPrivate();//PublicKey OutPut
ObjectOutputStream out = new ObjectOutputStream(
new FileOutputStream(args[1]));
out.writeObject(pubKey);
out.flush();
out.close();
//PrivateKey outPut
out = new ObjectOutputStream(
new FileOutputStream(args[2]));
out.writeObject(priKey);
out.close();
}else if(args[0].equals("-sign")){
ObjectInputStream inKey = new ObjectInputStream(
new FileInputStream(args[3]));
PrivateKey priKey = (PrivateKey) inKey.readObject();
inKey.close();
InputStream inSigFile = new FileInputStream(args[1]);
String sigFile = inSigFile.toString();
inSigFile.close();
Signature sig = Signature.getInstance("SHA1withDSA","BC");
sig.initSign(priKey);
sig.update(sigFile.getBytes());
byte[] siged = sig.sign();
OutputStream out = new FileOutputStream(args[2]);
out.write(siged);
out.close();
}else if(args[0].equals("-verSign")){
ObjectInputStream inKey = new ObjectInputStream(
new FileInputStream(args[3]));
PublicKey pubKey = (PublicKey) inKey.readObject();
inKey.close();
InputStream inSigFile = new FileInputStream(args[1]);
int Ch;
File sourcefile = new File(args[2]);
FileInputStream instream = new FileInputStream(sourcefile);
int length = (int) sourcefile.length();
byte[] sign = new byte[length];
instream.read(sign, 0, length);
instream.close();
Signature verSig = Signature.getInstance("SHA1withDSA","BC");
verSig.initVerify(pubKey);
while((Ch=inSigFile.read())!=-1){
verSig.update( (byte) Ch);
}
inSigFile.close();
if (verSig.verify(sign)) {
System.out.println("Verify Success");
}
else {
System.out.println("Verify Fail");
} }else if(args[0].equals("-help")){
System.out.println(
"用法:-genkeypairs publicKeyFileName privateKeyFileName!");
System.out.println("-encrypt plainFile encryptFile PublicKey");
System.out.println("-dscrypt encryptFile PrivateKey");
System.out.println("-sign orgFile signFile PrivateKey");
System.out.println("-versign orgFile signFile PublicKey");
System.exit(0);
} }
catch (IOException exception)
{
exception.printStackTrace();
}
catch (GeneralSecurityException exception)
{
exception.printStackTrace();
}
catch (ClassNotFoundException exception)
{
exception.printStackTrace();
} }
}
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2004-8-18
* Time: 13:33:15
* To change this template use File | Settings | File Templates.
*/
public class ReadByte {
public static void main(String[] args) {
try {
byte[] result;
File file = new File("ReadByte.java");
FileChannel fc = new RandomAccessFile(file, "r").getChannel();
ByteBuffer bf = ByteBuffer.allocate((int) fc.size()); fc.read(bf);
result = bf.array(); for (int i = 0; i < result.length; i++) {
System.out.print((char) result[i]);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}顺便问下楼主受什么刺激了?
为何"太伤心了"?