我在做文件操作的题(老师布置的) 我来解释一下就是生成三个文件先是写上那三个文件后做把第一第二加上第三n 时就用cat加在后面y 时就用cat覆盖 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;import java.awt.*;import java.awt.event.*;public class filework{ public static void copy(InputStream in,OutputStream out) throws IOException{ byte[] buf=new byte[1024]; int len=in.read(buf); while(len!=-1){ out.write(buf,0,len); len=in.read(buf); } } public static void overwritecat(String str1,String str2,String str3){ try{ InputStream in1=new FileInputStream(str1); OutputStream out1=new FileOutputStream(str2); copy(in1,out1); in1.close(); out1.close(); InputStream in2=new FileInputStream(str2); OutputStream out2=new FileOutputStream(str3,true); copy(in2,out2); in2.close(); out2.close(); }catch(IOException e){ System.out.println(e); } } public static void cat(String str1,String str2,String str3){ try{ InputStream in1=new FileInputStream(str1); OutputStream out1=new FileOutputStream(str2); copy(in1,out1); in1.close(); out1.close(); InputStream in2=new FileInputStream(str2); OutputStream out2=new FileOutputStream(str3); copy(in2,out2); in2.close(); out2.close(); }catch(IOException e){ System.out.println(e); } }public static void main(String args[]) throws IOException { System.out.println("please intput the first file"); byte buffer1[]=new byte[20]; System.in.read(buffer1,0,20); // String str1=new String(buffer1); File file1=new File("e:/javacode/str1.txt"); boolean t1=file1.isFile(); if(t1==false) System.out.println("file1 is no exited"); System.out.println("please intput the second file"); byte buffer2[]=new byte[20]; System.in.read(buffer2,0,20); String str2=new String(buffer2); File file2=new File("e:/javacode/str2.txt"); boolean t2=file2.isFile(); if(t2==false) System.out.println("file2 is no exited"); System.out.println("please intput the thrid file"); byte buffer3[]=new byte[20]; System.in.read(buffer3,0,20); String str3=new String(buffer2); File file3=new File("e:/javacode/str3.txt"); // File file3=new File("str3"); boolean t3=file3.isFile(); if(t3==false) System.out.println("file3 is no exited"); else{ System.out.println("you are should you overwrited n/y"); String ch=""; StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int j=tokenizer.nextToken(); if(j==tokenizer.TT_WORD){ ch=tokenizer.sval;} if(ch.equals("n")){ cat("e:/javacode/str1.txt","e:/javacode/str2.txt","e:/javacode/str3.txt"); System.out.println("sucess!") } if(ch.equals("y")){ overwritecat("e:/javacode/str1.txt","e:/javacode/str2.txt","e:/javacode/str3.txt"); System.out.println("sucessoverwrite!"); } } }} import java.io.*;import java.awt.*;import java.awt.event.*;public class filework{ public static void copy(InputStream in,OutputStream out) throws IOException{ byte[] buf=new byte[1024]; int len=in.read(buf); while(len!=-1){ out.write(buf,0,len); len=in.read(buf); } } public static void overwritecat(String str1,String str2,String str3){ try{ InputStream in1=new FileInputStream(str1); OutputStream out1=new FileOutputStream(str2); copy(in1,out1); in1.close(); out1.close(); InputStream in2=new FileInputStream(str2); OutputStream out2=new FileOutputStream(str3,true); copy(in2,out2); in2.close(); out2.close(); }catch(IOException e){ System.out.println(e); } } public static void cat(String str1,String str2,String str3){ try{ InputStream in1=new FileInputStream(str1); OutputStream out1=new FileOutputStream(str2); copy(in1,out1); in1.close(); out1.close(); InputStream in2=new FileInputStream(str2); OutputStream out2=new FileOutputStream(str3); copy(in2,out2); in2.close(); out2.close(); }catch(IOException e){ System.out.println(e); } }public static void main(String args[]) throws IOException { System.out.println("please intput the first file"); String str1; BufferedReader inn1=new BufferedReader(new InputStreamReader(System.in)); str1=inn1.readLine(); File file1=new File(str1); boolean t1=file1.isFile(); if(t1==false) System.out.println(str1+" is no exsited"); System.out.println("please intput the second file"); String str2; BufferedReader inn2=new BufferedReader(new InputStreamReader(System.in)); str2=inn2.readLine(); File file2=new File(str2); boolean t2=file2.isFile(); if(t2==false) System.out.println(str2+" is no exited"); System.out.println("please intput the thrid file"); String str3; BufferedReader inn3=new BufferedReader(new InputStreamReader(System.in)); str3=inn3.readLine(); File file3=new File(str3); boolean t3=file3.isFile(); if(t3==false) System.out.println(str3+" is no exited"); else{ System.out.println("you are should you overwrited n/y"); String ch=""; StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int j=tokenizer.nextToken(); if(j==tokenizer.TT_WORD){ ch=tokenizer.sval;} if(ch.equals("n")){ cat(str1,str2,str3); System.out.println("sucess!"); } if(ch.equals("y")){ overwritecat(str1,str2,str3); System.out.println("sucessoverwrite!"); } } }} import java.io.*;import java.awt.*;import java.awt.event.*;public class filework{ public static void copy(InputStream in,OutputStream out) throws IOException{ byte[] buf=new byte[1024]; int len=in.read(buf); while(len!=-1){ out.write(buf,0,len); len=in.read(buf); } } public static void overwritecat(String str1,String str2,String str3){ try{ InputStream in1=new FileInputStream(str1); OutputStream out1=new FileOutputStream(str2); copy(in1,out1); in1.close(); out1.close(); InputStream in2=new FileInputStream(str2); OutputStream out2=new FileOutputStream(str3,true); copy(in2,out2); in2.close(); out2.close(); }catch(IOException e){ System.out.println(e); } } public static void cat(String str1,String str2,String str3){ try{ InputStream in1=new FileInputStream(str1); OutputStream out1=new FileOutputStream(str2); copy(in1,out1); in1.close(); out1.close(); InputStream in2=new FileInputStream(str2); OutputStream out2=new FileOutputStream(str3); copy(in2,out2); in2.close(); out2.close(); }catch(IOException e){ System.out.println(e); } }public static void main(String args[]) throws IOException { System.out.println("please intput the first file"); String str1; BufferedReader inn1=new BufferedReader(new InputStreamReader(System.in)); str1=inn1.readLine(); File file1=new File(str1); boolean t1=file1.isFile(); if(t1==false) System.out.println(str1+" is no exsited"); System.out.println("please intput the second file"); String str2; BufferedReader inn2=new BufferedReader(new InputStreamReader(System.in)); str2=inn2.readLine(); File file2=new File(str2); boolean t2=file2.isFile(); if(t2==false) System.out.println(str2+" is no exited"); System.out.println("please intput the thrid file"); String str3; BufferedReader inn3=new BufferedReader(new InputStreamReader(System.in)); str3=inn3.readLine(); File file3=new File(str3); boolean t3=file3.isFile(); if(t3==false) System.out.println(str3+" is no exited"); else{ System.out.println("you are should you overwrited n/y"); String ch=""; StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); int j=tokenizer.nextToken(); if(j==tokenizer.TT_WORD){ ch=tokenizer.sval;} if(ch.equals("n")){ cat(str1,str2,str3); System.out.println("sucess!"); } if(ch.equals("y")){ overwritecat(str1,str2,str3); System.out.println("sucessoverwrite!"); } } }} java有没有中断方法运行的语句 求教实现字符串转换为执行语句的方法!~~~~~ tomcat下配置jsp,求高手指教! 50分帮忙查一个程序错误。有源代码 想写个泛型的NullOrEmpty,不知可行否? 一个JAVA的问题 送分了,极简单的入门问题! 咨询!java和Orcale 的认证考试! 请问 int compareTo(String other)怎么用啊 网页 gzip 解压 有谁写过将二进制的数据流与字符串相互转换的类 请问用JBuilder8怎么编辑一个600×480的Frame
import java.awt.*;
import java.awt.event.*;public class filework{
public static void copy(InputStream in,OutputStream out) throws IOException{
byte[] buf=new byte[1024];
int len=in.read(buf);
while(len!=-1){
out.write(buf,0,len);
len=in.read(buf);
}
}
public static void overwritecat(String str1,String str2,String str3){
try{
InputStream in1=new FileInputStream(str1);
OutputStream out1=new FileOutputStream(str2);
copy(in1,out1);
in1.close();
out1.close();
InputStream in2=new FileInputStream(str2);
OutputStream out2=new FileOutputStream(str3,true);
copy(in2,out2);
in2.close();
out2.close();
}catch(IOException e){
System.out.println(e);
}
}
public static void cat(String str1,String str2,String str3){
try{
InputStream in1=new FileInputStream(str1);
OutputStream out1=new FileOutputStream(str2);
copy(in1,out1);
in1.close();
out1.close();
InputStream in2=new FileInputStream(str2);
OutputStream out2=new FileOutputStream(str3);
copy(in2,out2);
in2.close();
out2.close();
}catch(IOException e){
System.out.println(e);
}
}
public static void main(String args[]) throws IOException {
System.out.println("please intput the first file");
byte buffer1[]=new byte[20];
System.in.read(buffer1,0,20);
// String str1=new String(buffer1);
File file1=new File("e:/javacode/str1.txt");
boolean t1=file1.isFile();
if(t1==false)
System.out.println("file1 is no exited"); System.out.println("please intput the second file");
byte buffer2[]=new byte[20];
System.in.read(buffer2,0,20);
String str2=new String(buffer2);
File file2=new File("e:/javacode/str2.txt");
boolean t2=file2.isFile();
if(t2==false)
System.out.println("file2 is no exited"); System.out.println("please intput the thrid file");
byte buffer3[]=new byte[20];
System.in.read(buffer3,0,20);
String str3=new String(buffer2);
File file3=new File("e:/javacode/str3.txt");
// File file3=new File("str3");
boolean t3=file3.isFile();
if(t3==false)
System.out.println("file3 is no exited");
else{
System.out.println("you are should you overwrited n/y");
String ch="";
StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int j=tokenizer.nextToken();
if(j==tokenizer.TT_WORD){
ch=tokenizer.sval;}
if(ch.equals("n")){
cat("e:/javacode/str1.txt","e:/javacode/str2.txt","e:/javacode/str3.txt");
System.out.println("sucess!")
}
if(ch.equals("y")){
overwritecat("e:/javacode/str1.txt","e:/javacode/str2.txt","e:/javacode/str3.txt");
System.out.println("sucessoverwrite!");
}
}
}
}
import java.awt.*;
import java.awt.event.*;public class filework{
public static void copy(InputStream in,OutputStream out) throws IOException{
byte[] buf=new byte[1024];
int len=in.read(buf);
while(len!=-1){
out.write(buf,0,len);
len=in.read(buf);
}
}
public static void overwritecat(String str1,String str2,String str3){
try{
InputStream in1=new FileInputStream(str1);
OutputStream out1=new FileOutputStream(str2);
copy(in1,out1);
in1.close();
out1.close();
InputStream in2=new FileInputStream(str2);
OutputStream out2=new FileOutputStream(str3,true);
copy(in2,out2);
in2.close();
out2.close();
}catch(IOException e){
System.out.println(e);
}
}
public static void cat(String str1,String str2,String str3){
try{
InputStream in1=new FileInputStream(str1);
OutputStream out1=new FileOutputStream(str2);
copy(in1,out1);
in1.close();
out1.close();
InputStream in2=new FileInputStream(str2);
OutputStream out2=new FileOutputStream(str3);
copy(in2,out2);
in2.close();
out2.close();
}catch(IOException e){
System.out.println(e);
}
}
public static void main(String args[]) throws IOException {
System.out.println("please intput the first file");
String str1;
BufferedReader inn1=new BufferedReader(new InputStreamReader(System.in));
str1=inn1.readLine();
File file1=new File(str1);
boolean t1=file1.isFile();
if(t1==false)
System.out.println(str1+" is no exsited"); System.out.println("please intput the second file");
String str2;
BufferedReader inn2=new BufferedReader(new InputStreamReader(System.in));
str2=inn2.readLine();
File file2=new File(str2);
boolean t2=file2.isFile();
if(t2==false)
System.out.println(str2+" is no exited"); System.out.println("please intput the thrid file");
String str3;
BufferedReader inn3=new BufferedReader(new InputStreamReader(System.in));
str3=inn3.readLine();
File file3=new File(str3);
boolean t3=file3.isFile();
if(t3==false)
System.out.println(str3+" is no exited");
else{
System.out.println("you are should you overwrited n/y");
String ch="";
StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int j=tokenizer.nextToken();
if(j==tokenizer.TT_WORD){
ch=tokenizer.sval;}
if(ch.equals("n")){
cat(str1,str2,str3);
System.out.println("sucess!");
}
if(ch.equals("y")){
overwritecat(str1,str2,str3);
System.out.println("sucessoverwrite!");
}
}
}
}
import java.awt.*;
import java.awt.event.*;public class filework{
public static void copy(InputStream in,OutputStream out) throws IOException{
byte[] buf=new byte[1024];
int len=in.read(buf);
while(len!=-1){
out.write(buf,0,len);
len=in.read(buf);
}
}
public static void overwritecat(String str1,String str2,String str3){
try{
InputStream in1=new FileInputStream(str1);
OutputStream out1=new FileOutputStream(str2);
copy(in1,out1);
in1.close();
out1.close();
InputStream in2=new FileInputStream(str2);
OutputStream out2=new FileOutputStream(str3,true);
copy(in2,out2);
in2.close();
out2.close();
}catch(IOException e){
System.out.println(e);
}
}
public static void cat(String str1,String str2,String str3){
try{
InputStream in1=new FileInputStream(str1);
OutputStream out1=new FileOutputStream(str2);
copy(in1,out1);
in1.close();
out1.close();
InputStream in2=new FileInputStream(str2);
OutputStream out2=new FileOutputStream(str3);
copy(in2,out2);
in2.close();
out2.close();
}catch(IOException e){
System.out.println(e);
}
}
public static void main(String args[]) throws IOException {
System.out.println("please intput the first file");
String str1;
BufferedReader inn1=new BufferedReader(new InputStreamReader(System.in));
str1=inn1.readLine();
File file1=new File(str1);
boolean t1=file1.isFile();
if(t1==false)
System.out.println(str1+" is no exsited"); System.out.println("please intput the second file");
String str2;
BufferedReader inn2=new BufferedReader(new InputStreamReader(System.in));
str2=inn2.readLine();
File file2=new File(str2);
boolean t2=file2.isFile();
if(t2==false)
System.out.println(str2+" is no exited"); System.out.println("please intput the thrid file");
String str3;
BufferedReader inn3=new BufferedReader(new InputStreamReader(System.in));
str3=inn3.readLine();
File file3=new File(str3);
boolean t3=file3.isFile();
if(t3==false)
System.out.println(str3+" is no exited");
else{
System.out.println("you are should you overwrited n/y");
String ch="";
StreamTokenizer tokenizer =new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
int j=tokenizer.nextToken();
if(j==tokenizer.TT_WORD){
ch=tokenizer.sval;}
if(ch.equals("n")){
cat(str1,str2,str3);
System.out.println("sucess!");
}
if(ch.equals("y")){
overwritecat(str1,str2,str3);
System.out.println("sucessoverwrite!");
}
}
}
}