我在 Python 3.5 中运行了这个:
import subprocess
subprocess.run(
'some_command --option <(zcat some_file_1.gz) <(zcat some_file_2.gz)',
shell=True
)
Run Code Online (Sandbox Code Playgroud)
得到这个错误:
/bin/sh: -c: line 0: syntax error near unexpected token `('
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激!
在我的 Java 应用程序中,我使用 LargeObject 接口编写 lo (大对象)类型的二进制数据:
LargeObjectManager lLOManager = ((org.postgresql.PGConnection) aDatabaseConnection).getLargeObjectAPI();
long oid = lLOManager.createLO();
LargeObject lo = lLOManager.open(oid, LargeObjectManager.WRITE);
if (aBLOB != null)
lo.write(aBLOB);
lo.close();
Run Code Online (Sandbox Code Playgroud)
读取表格时,我使用相同的 api 来获取输入流:
LargeObjectManager lLOManager = ((org.postgresql.PGConnection) aDatabaseConnection).getLargeObjectAPI();
long lOid = aRs.getLong(aIndex);
if (lOid != 0)
{
LargeObject lObj = lLOManager.open(lOid, LargeObjectManager.READ);
inputStream = lObj.getInputStream();
lObj.close();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试读取流时,出现异常:
int number = inputStream.read()
Run Code Online (Sandbox Code Playgroud)
或者替代地
byte[] byteArray = new byte[1024];
int number = inputStream.read(byteArray);
Run Code Online (Sandbox Code Playgroud)
例外:
org.postgresql.util.PSQLException:错误:无效的大对象描述符:0
我在这里总结了代码,因为在我的应用程序中它是分布式的。要点是,当流来自的数据库连接已经关闭时,当前会读取输入流中的内容。然而,这段代码以前可以在 postgres 上运行,现在仍然可以在 oracle 上运行。我尝试将 postgres 驱动程序 9.3 以及 …
我有一个InputStream作为参数,当我第一次读取它时它工作得很好,但是,读取相同的InputStream不起作用。我就是无法mark()上班reset()。有人知道如何重置这个吗?我正在读取 .txt 文件。该文件包含不会重新出现的敌方对象的生成值,因为输入流标记(?)位于末尾,我猜?
readTxt(InputStream resource){
//resource is a .txt as ResourceStream
arrayList = new BufferedReader(new InputStreamReader(resource,
StandardCharsets.UTF_8)).lines().collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud) 我需要列出目录的内容,但不包括纯文本文件中的已知文件列表.我假设使用grep或输入重定向或可能是一个while循环但是卡住了.
以下作品但是长篇大论:
ls ~/Library/Fonts | grep -v 'Onyx\|Playbill\|Georgia\|Garamond\|Tahoma\|Verdana\|Microsoft'
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏.
我已经实现了一个Java程序,它通过ServerSocket从GPS设备读取数据.
ServerSocket serverSocket = new ServerSocket(13811);
serverSocket.setReceiveBufferSize(receiveBufferSize);
Socket incomingSocket = serverSocket.accept();
InputStream stream = incomingSocket.getInputStream();
byte[] buffer = new byte[1000];
StringBuffer sb = new StringBuffer();
System.out.println("START getting message from TCP stream: " + dateFormat.format(Calendar.getInstance().getTime()));
while (stream.read(buffer) > 0)
{
sb.append(new String(buffer));
System.out.println(sb.toString());
}
System.out.println("[incomingMessage]: " + incomingMessage);
System.out.println("FINISHED getting message from TCP stream: " + dateFormat.format(Calendar.getInstance().getTime()));
Run Code Online (Sandbox Code Playgroud)
但是,我们发现存在很大的延迟(即Sys out"START ..."和"FINISHED ..."时间之间的偏差很大).花在inputStream.read()上的时间.
如果我使用Java客户端连接到上述服务器端口并向其发送数据,则服务器的inputStream可在几毫秒内读取该消息.下面显示了Java客户端代码.
Socket socket = new Socket("localhost", 13811);
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
String tobesend = "testing message 1";
out.writeBytes(tobesend); …Run Code Online (Sandbox Code Playgroud) 我试图访问一个文件进行xml解析:
InputStream inputStream = context.getAssets().open("/mnt/sdcard/cat/bird/flowers.xml");
Run Code Online (Sandbox Code Playgroud)
当它运行时,我得到以下错误:
06-13 23:13:22.620: W/System.err(3118): java.io.FileNotFoundException: /mnt/sdcard/cat/bird/flowers.xml
06-13 23:13:22.620: W/System.err(3118): at android.content.res.AssetManager.openAsset(Native Method)
06-13 23:13:22.620: W/System.err(3118): at android.content.res.AssetManager.open(AssetManager.java:314)
06-13 23:13:22.620: W/System.err(3118): at android.content.res.AssetManager.open(AssetManager.java:288)
Run Code Online (Sandbox Code Playgroud)
我检查了文件的拼写,我已经多次检查过该位置.该文件在那里并正确命名.这里发生了什么?
谢谢
我有这个方法:
private void unZipElementsTo(String inputZipFileName, String destPath) throws FileNotFoundException, IOException {
OutputStream out = null;
InputStream in = null;
ZipFile zf = null;
try {
zf = new ZipFile(inputZipFileName);
for (Enumeration<? extends ZipEntry> em = zf.entries(); em.hasMoreElements();) {
ZipEntry entry = em.nextElement();
String targetFile = destPath + FILE_SEPARATOR + entry.toString().replace("/", FILE_SEPARATOR);
File temp = new File(targetFile);
if (!temp.getParentFile().exists()) {
temp.getParentFile().mkdirs();
}
in = zf.getInputStream(entry);
out = new FileOutputStream(targetFile);
byte[] buf = new byte[4096];
int len;
while ((len = in.read(buf)) > …Run Code Online (Sandbox Code Playgroud) 我正在用Java编写一个函数来逐行读取PHP.我注意到有些行被跳过了.
Java中的函数:
public String ReadContentRegex(String path, String Regex) throws
FileNotFoundException, IOException
{
final StringBuilder contents = new StringBuilder();
BufferedReader br = new BufferedReader(
new InputStreamReader(new FileInputStream(path)));
try {
String line;
while ((line = br.readLine()) != null) {
System.out.println(br.readLine());
}
} finally {
br.close();
}
return contents.toString();
}
Run Code Online (Sandbox Code Playgroud)
Java应该使用的PHP文件BufferedReader:
<?php #if (!APP_ACT) exit();
class dbtest extends Codeplexon\core\fwcontroller {
public $name = __CLASS__;
static function destruct()
{
// ili 404
echo("Error function: ".__FUNCTION__);
}
public function db()
{
$model = …Run Code Online (Sandbox Code Playgroud) 这是我在网上找到的一个Java示例:
try{
//use buffering
InputStream file = new FileInputStream("quarks.ser");
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new ObjectInputStream (buffer);
try{
//deserialize the List
List<String> recoveredQuarks = (List<String>)input.readObject();
//display its data
for(String quark: recoveredQuarks){
System.out.println("Recovered Quark: " + quark);
}
}
finally{
input.close();
}
} catch(ClassNotFoundException ex){
//some exception handling
}
Run Code Online (Sandbox Code Playgroud)
在上面,使用try-finally块在关闭输入之前使用输入执行某些处理有什么好处?换句话说,上面的代码对这样的东西有什么好处:
try{
//use buffering
InputStream file = new FileInputStream("quarks.ser");
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new ObjectInputStream (buffer);
List<String> recoveredQuarks = (List<String>)input.readObject();
for(String quark: recoveredQuarks){
System.out.println("Recovered Quark: …Run Code Online (Sandbox Code Playgroud) 我想打开资产文件.在java代码工作之前,但当我将代码更改为kotlin时,它不起作用.
Java代码的工作原理
InputStream streamIN = new BufferedInputStream(context.getAssets().open(Database.ASSET));
OutputStream streamOU = new BufferedOutputStream(new FileOutputStream(LOCATION));
byte[] buffer = new byte[1024];
int length;
while ((length = streamIN.read(buffer)) > 0) {
streamOU.write(buffer, 0, length);
}
streamIN.close();
streamOU.flush();
streamOU.close();
Run Code Online (Sandbox Code Playgroud)
我将代码更改为Kotlin但它不起作用
var length: Int
val buffer = ByteArray(1024)
BufferedOutputStream(FileOutputStream(LOCATION)).use {
out ->
{
BufferedInputStream(context.assets.open(Database.ASSET)).use {
length = it.read(buffer)
if (length > 0) out.write(buffer, 0, length)
}
out.flush()
}
}
Run Code Online (Sandbox Code Playgroud) inputstream ×10
java ×6
android ×2
bash ×2
exception ×1
file-io ×1
flush ×1
kotlin ×1
macos ×1
postgresql ×1
python-3.x ×1
readfile ×1
resultset ×1
sockets ×1
sonarqube ×1
tcp ×1
try-finally ×1
zcat ×1