我得到java.lang.NullPointerException
的 while ((len = in.read(buf , 0 , buf.length)) >= 0)
在下面的方法:
public void copy(String src, File dst) throws IOException {
InputStream in = getClass().getResourceAsStream(src);
OutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1012];
int len;
while ((len = in.read(buf , 0 , buf.length)) >= 0) {
out.write(buf, 0, len);
buf = null;
}
in.close();
out.close();
}
Run Code Online (Sandbox Code Playgroud)
我没有得到它.如果我得到解决方案,我会很感激.谢谢你提前.......
我有一个阵列 char input[11] = {'0','2','7', '-','1','1','2', ,'0','0','9','5'};
如何将输入[0,1,2]转换为int one = 27
输入[3,4,5,6] int two = -112
并输入[7,8,9,10]为int three = 95
?
是的,JNK
如何将此VBNet代码转换为C#?(ByteToImage
是一个用户定义的函数使用,以字节数组转换成位图.
Dim Bytes() As Byte = CType(SQLreader("ImageList"), Byte())
picStudent.Image = jwImage.ByteToImage(Bytes)
Run Code Online (Sandbox Code Playgroud)
我试过了
byte[] Bytes = Convert.ToByte(SQLreader("ImageList")); // Error Here
picStudent.Image = jwImage.ByteToImage(Bytes);
Run Code Online (Sandbox Code Playgroud)
但它会产生错误说: Cannot implicitly convert type 'byte' to 'byte[]'
我正在做的基本上是将图像从数据库转换为字节数组并将其显示在图片框上.
我试图转换包含普通字符和'_',';'和'='的sqlstring,当我尝试这样做时:
Byte[] byt = Convert.FromBase64String(value);
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
Run Code Online (Sandbox Code Playgroud)
Additonal: - 我用它来加密sqlstring -my解密,它使用同样的功能工作正常,但在尝试转换回加密时失败
我有两个字节数组.我想将这两个字节数组合并为一个字节数组.
通常,我只是创建一个新的字节数组,其长度为= byte array#1 + byte array#2.然后将字节数组#1和#2复制到新的字节数组.
有没有一种更有效的方法来使用VB.NET和.NET 4合并两个字节数组?
数组byte []包含照片的完美逐字节副本,当我尝试将byte []转换为String并使用它写入文件时,它会失败.
我需要转换为字符串以便稍后通过套接字发送它.
我的每个连接的处理程序都有一个Socket(sock),PrintWriter(out)和BufferedReader(in),然后我将Socket与PrintWriter和BufferedReader相关联.有了这个,我发送和接收字符串out.println和in.readLine.
我怎样才能解决这个问题?
测试代码:
// getPhoto() returns byte[]
String photo = new String(getPhoto());
// Create file
DataOutputStream os = new DataOutputStream(new FileOutputStream("out1.jpg"));
// This makes imperfect copy of the photo
os.writeBytes(photo);
//This works perfectly basically it copies the image through byte[]
//os.write(getPhoto());
// Close the output stream
os.close();
Run Code Online (Sandbox Code Playgroud) 我正在编写一个Java程序,它使用RSA加密给定的文本,并将加密的字节(byte []数组)保存在.txt文件中.有一个单独的解密程序读取这些字节.现在我想将相同的字节读入解密程序的byte []中.如何使用Java完成?
BufferedReader brip = new BufferedReader(new FileReader("encrypted.txt"));
Strings CurrentLine = brip.readLine();
byte[] b = sCurrentLine.getBytes();
Run Code Online (Sandbox Code Playgroud)
这就是我从文件中读取数据的方式.但这是错误的,因为它将sCurrentLine变量中的字节转换为再次字节.
所以我有一个字节数组,我需要从中删除前5个元素.无论如何,我在网上看了一下,找不到任何适合我想要的东西.所以我做了这个,它本质上是非常缓慢的,无法使用.
private byte[] fR(byte[] tb)
{
string b = "";
byte[] m = new byte[tb.Length - 5];
for (int a = 5; a < tb.Length; a++)
{
b = b + " " + tb.GetValue(a);
}
b = b.Remove(0, 1);
string[] rd = Regex.Split(b, " ");
for (int c = 0; c < rd.Length; c++)
{
byte curr = Convert.ToByte(rd[c]);
m.SetValue(curr, c);
}
return m;
}
Run Code Online (Sandbox Code Playgroud)
我要问的是,是否有办法让这更快/更好.或者我可以从字节数组中删除前5个元素的另一种方法.