62,621
社区成员
发帖
与我相关
我的任务
分享import java.io.*;
public class PrintStream6 {
public static void main(String args) {
String filename = args;
String path = null;
if(args.length < 2) {
} else {
path = args;
}
BufferedReader br = null;
if (filename != null) {
if(path != null) {
printlist(filename,path);
}else {
printlist(filename,System.out);
}
}
}
public static void printlist(String f,PrintStream ps) {
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String s = null;
while((s = br.readLine()) != null) {
ps.println(s);
}
ps.close();
fr.close();
br.close();
} catch(IOException e) {
ps.println("文件无法读取!");
}
}
public static void printlist(String f,String path) {
FileWriter fw = null;
FileReader fr = null;
BufferedReader br = null;
int number = 0;
try {
fr = new FileReader(f);
br = new BufferedReader(fr);
String s = null;
//File pathname = new File(path);
fw = new FileWriter(path);
//BufferedWriter br1 = new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(fw);
while((s = br.readLine()) != null) {
System.out.println(s);
pw.println(s);//这里怎么写文件写不进去??感觉这句话没执行一样
number++;
}
System.out.println(number + "个字符!");
fr.close();
br.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
//运行是:java PrintStream6 PrintStream6.java d:\\sss.txtimport java.io.*;
public class PrintStream6 {
public static void main(String[] args) {
String filename = args[0];
String path = null;
if(args.length < 2) {
} else {
path = args[1];
}
BufferedReader br = null;
if (filename != null) {
if(path != null) {
printlist(filename,path);
}else {
printlist(filename,System.out);
}
}
}
public static void printlist(String f,PrintStream ps) {
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String s = null;
while((s = br.readLine()) != null) {
ps.println(s);
}
ps.flush();
ps.close();
fr.close();
br.close();
} catch(IOException e) {
ps.println("文件无法读取!");
}
}
public static void printlist(String f,String path) {
FileReader fr = null;
FileWriter fw = null;
try {
int s;
fr = new FileReader(f);
fw = new FileWriter(path);
while((s = fr.read()) != -1) {
fw.write(s);
System.out.print((char)s);
}
fw.flush();
fr.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}