我惊讶地发现,今天,我不能追查任何简单的方法的内容写入InputStream到OutputStreamJava中.显然,字节缓冲区代码并不难写,但我怀疑我只是遗漏了一些会让我的生活更轻松(代码更清晰)的东西.
那么,给定一个InputStream in和一个OutputStream out,是否有更简单的方法来编写以下内容?
byte[] buffer = new byte[1024];
int len = in.read(buffer);
while (len != -1) {
out.write(buffer, 0, len);
len = in.read(buffer);
}
Run Code Online (Sandbox Code Playgroud) Image和BufferedImage有什么区别?
我可以直接从图像源"image.png"创建BufferedImage吗?
我需要找到Windows上给定文件的默认文件打开器,以便我可以自定义命令参数并使用默认的opener/viewer打开文件.
我的实际使用场景是使用用户的默认媒体播放器打开多个多媒体文件,以便将所有文件添加到用户的播放列表中(对于可以在同一个媒体上打开多个文件的播放器).对于Windows以外的操作系统我使用Desktop.open(File file)方法(我根本不关心为Windows以外的操作系统打开多个文件功能),我找不到任何方法可以打开多个文件而不是自定义命令参数并使用exec()方法运行它运行时类.我使用类似于此的somethig:
private void playItems2(List<File> fileList, String playerBinary) {
String args = " ";
for (File file : fileList) {
args += "\"" + file.getAbsolutePath() + "\" ";
}
try {
String command = playerBinary + args;
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(command);
} catch (Exception exc) {/*handle exception*/
System.err.println("Run Player Exc:" + exc.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用用户指定的路径playerBinary,我需要的是自动检测第一项的默认播放器fileList并将其用作playerBinary.
我还查看了Rundll32.exe和cmd.exe/start解决方案,但它们对我的使用场景不起作用.