如果你的存储方法用得好的话,你读取时会很方便的,并不像你现在这样难。example: file.iniusername=abc
age=22
gender=1
age=22
gender=1
解决方案 »
- 这题我选 c
- 请问,JAVA有没有可以由日期判断出星期几的类
- Thread.currentThread().setContextClassLoader()问题,肯定给分
- String 怎么转化成Int?
- 关于递归算法,急!回答满意给30分!
- 求Hibernate学习资料
- 一个简单的类型转换问题,请高手帮忙解决!---thanks
- 哪里有 2003年度Javaworld编辑奖最佳Java书籍的下载,例如Patterns of Enterprise Application Architecture
- weblogic的问题
- 这下坏了!中文!中文!
- Runtime.getRuntime().exec抛出异常,不知为何?
- 关于图形对象的文件存储问题。
Byte b[4] 里面的是一个Int的二进制数,那么如何转为整数?
不会是
int a=b;
这样就行了吧???
比如你的b[]={1,1,0,1},b[0]存高位,那就做一个循环,从高往低累加,结果是c=1*2^3+1*2^2+0*2^1+1*2^0,c就是你要的int值了。
for (int i = 0; i < 4; i++){
a += ( ( int )b[ i ] ) << 8;
}
for (int i = 0; i < 4; i++){
a += ( ( int )b[ i ] ) << 8;
}
int index;
for ( index = 0; index < 3; index++){
a += ( ( int )b[ index ] ) << 8;
}
a += b[ index ]; System.out.println( "a= " + a);
int index;
for ( index = 0; index < 3; index++){
a = ( b[ index ] + a) << 8;
}
a += b[ index ]; System.out.println( "a= " + a);又错了,运算优先级搞错了,这回肯定没问题了,结果测试过了:(错了这么多次才写对,真他妈的并:(
哈哈,哈哈哈
int c;
for ( int i = 0; i < 4; i++){
c=a;
c = c << ( i * 8 );
b[ i ] = ( byte )( c >> ( 3 * 8 ) );
System.out.println( "b[ " + i + " ] = " + b[ i ]);
}
int c;
for ( int i = 0; i < 4; i++){
c=a;
c = c << ( i * 8 );
b[ i ] = ( byte )( c >> ( 3 * 8 ) );
System.out.println( "b[ " + i + " ] = " + b[ i ]);
}
System.out.println(Integer.toBinaryString(a));
结果::
b[ 0 ] = 0
b[ 1 ] = 1
b[ 2 ] = 1
b[ 3 ] = 1
10000000100000001哈哈哈不行了