我的用例要求我打开一个txt文件,比如abc.txt,它位于一个zip存档中,其中包含表单中的键值对
键1 =值
键2 =值
..等等每个键值对在一个新行中.我必须更改与某个键对应的一个值,并将文本文件放回到存档的新副本中.我怎么在java中这样做?
我到目前为止的尝试:
ZipFile zipFile = new ZipFile("test.zip");
final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("out.zip"));
for(Enumeration e = zipFile.entries(); e.hasMoreElements(); ) {
ZipEntry entryIn = (ZipEntry) e.nextElement();
if(!entryIn.getName().equalsIgnoreCase("abc.txt")){
zos.putNextEntry(entryIn);
InputStream is = zipFile.getInputStream(entryIn);
byte [] buf = new byte[1024];
int len;
while((len = (is.read(buf))) > 0) {
zos.write(buf, 0, len);
}
}
else{
// I'm not sure what to do here
// Tried a few things and the file gets corrupt
}
zos.closeEntry();
}
zos.close();
Run Code Online (Sandbox Code Playgroud) 很抱歉标题不清楚,实际上我无法想到一个简洁地描述我的问题的标题.
但问题很简单.我有一个Node类.我希望通过其id_字段维护其对象之间的顺序.我知道如果我在Node类中重载<运算符或在multiset中提供Comparator对象,那么创建多节点<Node>将正确维护容器中的顺序.但我想声明一个multiset <Node*>容器,并希望实现相同的行为.
这是我的Node类定义:
class Node {
int id_;
...
public:
Node() {
...
}
int getId() {
return id_;
}
void setId(int id) {
id_ = id;
}
...
bool operator<(const Node &input) {
return (this->id_ < input.id_);
}
};
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
这有什么问题?
#include <stdio.h>
void main(){
char *s="some text";
printf("%d",is_in(s,'t'));
}
int is_in(char *s, char c){
while(*s){
if(*s==c) return 1;
s++;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在GCC中遇到以下编译时错误:
test.c:9:错误:'is_in'的冲突类型
test.c:9:注意:具有默认促销的参数类型不能与空参数名称列表声明匹配
test.c:5:注意:'is_in'之前的隐式声明就在这里
它应该给我输入用户输入的数量.但它给了100.我用gcc编译.
#include <stdio.h>
int arr[100];
int count=0;
int max=100;
int main(){
int i, input;
printf("Enter integer values one by one, q to quit.\n");
for(i=0;i<max;i++){
scanf("%d",&input);
arr[i]=input;
if(input=='q')break;
count++;
}
printf("You entered %d values.\n",count);
return 0;
}
Run Code Online (Sandbox Code Playgroud)