最近在做下载方面的开发.有一个需求,就是读取要下载的文件中的一些数据,比如要读取这个文件包含的用户信息,但是怎么读都不对.后来搞了很久才发现,服务器上的文件里的用户信息,用C#写的存储方法来存储的,而我在读取时的操作是用java写的,关键的一点是,c#中的byte范围是[0-255],java的是[-128,127],所以导致了我用byte[]数组读取数据时,如果那一位的数据超过127就会变成负数. 需要进行转换: int data[] = new int[b.length]; for(int
using System; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; namespace Dscf.Global.Utils { public class ObjectUtils { /// <summary> /// 对像转成 byte 数组 /// <
Java中涉及byte.short和char类型的运算操作首先会把这些值转换为int类型,然后对int类型值进行运算,最后得到int类型的结果.因此,如果把两个byte类型值相加,最后会得到一个int类型的结果.如果需要得到byte类型结果,必须将这个int类型的结果显式转换为byte类型.例如,下面的代码会导致编译失败:class BadArithmetic { static byte addOneAndOne() { byte a = 1; byte b = 1; byte c = (a +
Encoding类 表示字符编码 1.字符串转换成字节数组byte[] using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FileStreamTest { class Program { static void Main(string[] args) {