文件拷贝,重现重复内容怎么办

Eniak Eniak 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想通过一个程序复制一个java文件,也就是将 A.java 复制到 B.java 中去,

但是再复制的时候,出现了重复出现的情况,

也就是,程序好像讲缓冲区前面的部分重新写了一遍

大家说说应该怎么解决呢,嗯,上代码


//复制的代码,感觉在缓冲区的时候有点问题
class FileCopy
{
FileInputStream FIS;
FileOutputStream FOS;

public boolean copyFile(File src, File des) {

try {
FIS = new FileInputStream(src);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
FOS = new FileOutputStream(des);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

byte[] bt = new byte[1024];
int readNum = 0;
try {
while( (readNum = FIS.read(bt)) != -1 ) {
FOS.write(bt, 0,bt.length);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

try {
FIS.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
FOS.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
}


只选取了文件的结尾部分

public class register_inquiry extends Domain
{
public register_inquiry()
{
TermVariable.initialize(2);

constants = new String[3];
constants[0] = "in";
constants[1] = "information";
constants[2] = "tool";

compoundTasks = new String[1];
compoundTasks[0] = "register_inquiry";

primitiveTasks = new String[1];
primitiveTasks[0] = "!register";

methods = new Method[1][];

methods[0] = new Method[1];
methods[0][0] = new Method0();


ops = new Operator[1][];

ops[0] = new Operator[1];
ops[0][0] = new Operator0();

axioms = new Axiom[3][];

axioms[0] = new Axiom[0];

axioms[1] = new Axiom[0];

axioms[2] = new Axiom[0];

}
}


只选取了文件的结尾部分

public class register_inquiry extends Domain
{
public register_inquiry()
{
TermVariable.initialize(2);

constants = new String[3];
constants[0] = "in";
constants[1] = "information";
constants[2] = "tool";

compoundTasks = new String[1];
compoundTasks[0] = "register_inquiry";

primitiveTasks = new String[1];
primitiveTasks[0] = "!register";

methods = new Method[1][];

methods[0] = new Method[1];
methods[0][0] = new Method0();


ops = new Operator[1][];

ops[0] = new Operator[1];
ops[0][0] = new Operator0();

axioms = new Axiom[3][];

axioms[0] = new Axiom[0];

axioms[1] = new Axiom[0];

axioms[2] = new Axiom[0];

}
}
//重复出现的部分
switch (which)
{
case 0:
p = (new Precondition0(unifier)).setComparator(null);
break;
default:
return null;
}

p.reset();

return p;
}

public String getLabel(int which)
{
switch (which)
{
case 0: return "Method0Branch0";
default: return null;
}
}
}

public class reg
//重复出现的情况结束
...全文
评论 8
收藏 已收藏
分享
返回顶部
Eniak
Java SE 62,621 成员 307,251 内容