- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
如何从Java文件中获取短(16位)数组?
这是我尝试的:
final static String FILE_NAME_INPUT = "./example.txt";
public static void main(String[] args) {
readFile(FILE_NAME_INPUT);
}
public static void readFile(String filename) {
short[] buffer = null;
File a_file = new File(filename);
try {
File file = new File(filename);
FileInputStream fis = new FileInputStream(filename);
DataInputStream dis = new DataInputStream(fis);
int length = (int)a_file.length();
buffer = new short[length];
//dis.readShort(buffer); DOESN'T WORK
for(int i = 0; i < length; i++) {
System.out.println("buffer[" + i + "]: " + buffer[i]);
}
dis.close();
}
catch(FileNotFoundException fe) {
System.out.println("FileNotFoundException: " + fe);
}
catch(IOException ioe) {
System.out.println("IOException: " + ioe);
}
}
dis.readShort(buffer)
不起作用,因为
readShort()
必须没有参数。
最佳答案
您的缓冲区数组为空,但是如果要检查DataInputStream
,可以使用类似的内容
int counter =0;
while(dis.available()>0)
{
// read two bytes from data input
short s = dis.readShort();
// print the short value
buffer[counter] = s;
System.out.print(s+" ");
counter++;
}
关于java - 简写为[],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35752048/
考虑以下示例: if (cache) { x = cache; } else { x = cache = someMethod(); } 无论如何要使它比 cache 更短? x =
我有一个字符串,我想将它附加到其他字符串。比方说: $my_string = 'Hello'; $my_string .= ' there'; 这将返回“你好”。 我想像这样设置条件: $my_str
有没有办法执行以下操作,但简而言之 if/then 语法: if($method->isAbstract()) { $details['abstract'] = true; } 如果我这样做:
我很好奇,有没有更简单的说法 if(myVar == myVal || myVar == myOtherVal){ /*...*/ } 如: if(myVar == myVal || myOtherV
我正在寻找一种方法来最小化数组的创建,其中所有索引都具有相同的值。这可能不可能,但我会发现它非常方便。 考虑: var layer = []; layer['game'] = new Kinetic.
我想知道是否有办法将简写 if/else 与简写 += 合并 类似这样的事情: var value; $.each(data.events, function(index, element) {
我需要用 JQuery 做一个速记 IF-ELSE。我的代码: $('#somediv').val() != 0 ? $('#somediv').toggleClass('class1') :
我觉得这一定是重复的,但我找不到任何东西,可能是由于措辞不同,或者只是因为确实没有更好的东西。 我正在生成大量的 JS 代码,其中“OR”对象属性与变量,而标识符不一定匹配。看起来像这样(值为 boo
这个问题在这里已经有了答案: Shorthand if/else statement Javascript (7 个答案) 关闭 9 年前。 下面的简写等价物是什么? if (windowwidth
以下的 JS 简写是什么: if (typeof bfMax !== 'undefined') { options.max = bfMax; } 最佳答案 有条件地赋值
假设我有父类 - “Parent”,我想从中创建三个对象 - o1、o2、o3。 因此,如果有一个简略的方法或一种漂亮的方法来执行以下操作: o1=Parent() o2=Parent() o3=Pa
这个问题已经有答案了: Check variable equality against a list of values (16 个回答) 已关闭 5 年前。 我觉得我经常遇到这种情况,直觉上应该有一
我是 Swift 的新手,我想知道是否有一种“速记”形式,可以在不执行 if nil 检查的情况下将可选值分配给非可选值。 例如,如果我有一个可选的闭包: var onTap: (() -> Void
这个问题在这里已经有了答案: Why does the expression 0 < 0 == 0 return False in Python? (9 个回答) 关闭 4 年前。 if x ==
这个问题在这里已经有了答案: CSS select multiple descendants of another element (3 个答案) 关闭 5 年前。
假设我正在使用一些 python 包中的类,如下所示 class foo(object): def __init__(self): self.a = None
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 8 年前。 Improve t
top right bottom left 或 width 有任何简写和高度 ? 我有很多这样的CSS #topDiv { position:absolute; top:0px;
这个问题在这里已经有了答案: 关闭9年前。 Possible Duplicate: Ternary conditional operator in Python 我想在 python 中做以下事情:
if-else 的 JavaScript 简写可以从函数中返回吗?如果是这样,这将如何运作。 例如。我有这个: if(boolean){ return; } 我想这样写: (value)? retu
我是一名优秀的程序员,十分优秀!