通常,当我处理InputStream, 停止读取的条件是当读取字节数小于或等于 0
例如,
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
Run Code Online (Sandbox Code Playgroud)
但是,当我查看文档时 InputStream
https://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html#read(byte[])
只有我注意到
-1 如果由于已到达流末尾而没有更多数据。
我想知道,我应该将我的代码重构为
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) != -1) {
if …Run Code Online (Sandbox Code Playgroud) 我有以下两个表,附属机构和推荐人.
附属公司表
id loginid
3 CR0007
2 CR5604
4 VRTC0008
Run Code Online (Sandbox Code Playgroud)
推荐人表
id affiliates_id loginid
3 2 MLT29710
4 3 MX0001
Run Code Online (Sandbox Code Playgroud)
如果我想知道,联盟会员与推荐人相关联,我可以简单地使用以下查询:
SELECT affiliates.loginid affiliates_loginid, referrers.loginid referrers_loginid FROM affiliates, referrers WHERE affiliates.id = referrers.affiliates_id
Run Code Online (Sandbox Code Playgroud)
结果表
affiliates_loginid referrers_loginid
CR5604 MLT29710
CR0007 MX0001
Run Code Online (Sandbox Code Playgroud)
如果,我想知道,哪个会员与任何推荐人无关,该怎么办?我可以使用的单个SQL语句是什么?将where子句更改为 affiliates.id!= referrers.affiliates_id当然不起作用.
我的预期结果是VRTC0008,因为该联盟会员与任何推荐人无关.
假设我正在设计一个接口,以返回子类的名称.请注意,对于子类的不同实例,它们的名称应保持不变.
为了提高速度和内存效率,我想说第三种方法签名可能是最好的(根据char*vs cd中的std :: string的一些注释)
virtual const std::string& name2() const = 0;
Run Code Online (Sandbox Code Playgroud)
我想知道有更好的选择吗?
#include <cstdio>
#include <string>
class baby_interface {
public:
virtual const char* name0() const = 0;
virtual std::string name1() const = 0;
virtual const std::string& name2() const = 0;
};
class baby : public baby_interface {
public:
virtual const char* name0() const
{
return "My Baby";
}
virtual std::string name1() const
{
return "My Baby";
}
virtual const std::string& name2() const
{
return std::string("My Baby");
} …Run Code Online (Sandbox Code Playgroud) alt text http://sites.google.com/site/yanchengcheok/Home/help-remove-dot-line.png?attredirects=0
每当在超链接上发生点击事件时,我将使用JavaScript来切换下拉菜单的显示.但是,我意识到还会有一个包围超链接的虚线矩形.我可以知道如何在点击后明确删除虚线矩形吗?
可能重复:
static const vs #define
大家好,在C++中,要定义一个在整个应用程序中使用的常量,你们通常的做法是什么?
#define WINDOWS_HEIGHT 1024
Run Code Online (Sandbox Code Playgroud)
要么
const int WINDOWS_HEIGHT = 1024;
Run Code Online (Sandbox Code Playgroud)
谢谢.
我能够通过网络浏览器启动开放式办公室,即使我没有开放式办公室的副本.
我可以知道背后的技术是什么?
(虽然推出的开放办公室很慢但没有响应)
谢谢.
当我有一个公开暴露的类时,我通常将其成员变量与公共访问器和变换器一起私有(我尽量避免使用mutators来使我的类不可变).
例如,
public class Point {
private final int x;
private final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
Run Code Online (Sandbox Code Playgroud)
如果课程是私人使用,我通常会
private static class Point {
public final int x;
public final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
Run Code Online (Sandbox Code Playgroud)
我发现第二种方式对我来说更方便.虽然一个好的IDE可能会有所帮助,但不那么麻烦且不那么打字.
我想知道,如果我有一个公共消费课程,我使用第二种方法是否好?(通过确保我的公开暴露字段将是不可变的).
有什么缺点吗?虽然它似乎违反了OOP封装理论,但从实际的角度来看,我并没有看到真正的危害.
我想知道,Executors.newSingleThreadExecutor()和Executors.newFixedThreadPool(1)之间有什么区别
以下是从javadoc中选取的
与其他等效的newFixedThreadPool(1)不同,保证返回的执行程序不可重新配置以使用其他线程.
我尝试下面的代码,似乎没有区别.
package javaapplication5;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author yan-cheng.cheok
*/
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
//ExecutorService threadExecutor = Executors.newSingleThreadExecutor();
ExecutorService threadExecutor = Executors.newFixedThreadPool(1);
threadExecutor.submit(new BadTask());
threadExecutor.submit(new Task());
}
class BadTask implements Runnable {
public void run() {
throw new RuntimeException();
}
}
class Task implements Runnable {
public void run() {
for (int i = …Run Code Online (Sandbox Code Playgroud) 我意识到我无法通过替换价值LinkedList.Enumerator.
例如,我尝试将以下Java代码移植到C#:
Java代码:
ListIterator<Double> itr1 = linkedList1.listIterator();
ListIterator<Double> itr2 = linkedList2.listIterator();
while(itr1.hasNext() && itr2.hasNext()){
Double d = itr1.next() + itr2.next();
itr1.set(d);
}
Run Code Online (Sandbox Code Playgroud)
C#代码:
LinkedList<Double>.Enumerator itr1 = linkedList1.GetEnumerator();
LinkedList<Double>.Enumerator itr2 = linkedList2.GetEnumerator();
while(itr1.MoveNext() && itr2.MoveNext()){
Double d = itr1.Current + itr2.Current;
// Opps. Compilation error!
itr1.Current = d;
}
Run Code Online (Sandbox Code Playgroud)
我可以使用的任何其他技术?
目前,我可以Shape通过Canvas添加各种
canvas.Children.Add(line);
canvas.Children.Add(polyLine);
//...
Run Code Online (Sandbox Code Playgroud)
但是,我们如何绘制具有各种字体大小、字体类型……的文本呢?