FileInputStream fi = null;
try {
fi = new FileInputStream(file);//file是源文件
}
catch (FileNotFoundException ex) {
} FileOutputStream fo = null;
try {
fo = new FileOutputStream(path1);//path1是文件路径
}
catch (FileNotFoundException ex1) {
}
int temp;
try {
while ( (temp = fi.read()) != -1) {
fo.write(temp);
}
}
catch (IOException ex2) {
}
try {
fi.close();
}
catch (IOException ex3) {
}
try {
fo.close();
}
catch (IOException ex4) {
}
try {
fi = new FileInputStream(file);//file是源文件
}
catch (FileNotFoundException ex) {
} FileOutputStream fo = null;
try {
fo = new FileOutputStream(path1);//path1是文件路径
}
catch (FileNotFoundException ex1) {
}
int temp;
try {
while ( (temp = fi.read()) != -1) {
fo.write(temp);
}
}
catch (IOException ex2) {
}
try {
fi.close();
}
catch (IOException ex3) {
}
try {
fo.close();
}
catch (IOException ex4) {
}
fi = new FileInputStream(args[0]);//file是源文件
FileOutputStream fo = null;
fo = new FileOutputStream(args[1]);//path1是文件路径
int temp;
while ( (temp = fi.read()) != -1) {
fo.write(temp);
}
fi.close();
fo.close();}本程序是根据 pingchuan2003(啊盟) 代码所改, pingchuan2003(啊盟)写得很对。
我只是补充一下,希望 pingchuan2003(啊盟) 不要介意,我可以不要分。
希望楼主给 pingchuan2003(啊盟) 分数。祝你好运!
}
fi = new FileInputStream(args[0]);//file是源文件
FileOutputStream fo = null;
fo = new FileOutputStream(args[1]);//path1是文件路径
int temp;
while ( (temp = fi.read()) != -1) {
fo.write(temp);
}
fi.close();
fo.close();}
}对不起,上面笔误,把说明写在了 大括号的里面。祝你好运!
import java.io.*;
//java FileIO c:\a.txt
class copy_file
{
public static void copyfile1(String path1,String path2) throws IOException //使用FileInputStream和FileOutStream
{
FileInputStream fi=new FileInputStream(path1);
FileOutputStream fo=new FileOutputStream(path2);
byte data[]=new byte[fi.available()];
fi.read(data);
fo.write(data);
fi.close();
fo.close();
}
}public class FileIO
{
public static void main(String[] args) throws IOException
{
String aline,st,tmp;
int flag,i;
if (args.length ==0)
{
System.out.println("Parameters not found!");
System.exit(0);
}
System.out.println("File deal....."+args[0]);
FileOutputStream out1=new FileOutputStream("tmp.txt");
FileInputStream in1=new FileInputStream(args[0]);
DataInputStream in=new DataInputStream(in1);
DataOutputStream out=new DataOutputStream(out1);
aline=in.readLine();
int ii=0;
while(aline!=null){
st=aline.trim();
System.out.println(ii++);
System.out.println(aline+" ,len:"+st.length());
if (st.length()>0)
{
if (st.charAt(0)>='0' && st.charAt(0)<='9')
{
flag=1;
i=0;
tmp="";
while((flag==1) && (i<aline.length()) ){
if ((aline.charAt(i)>='0' && aline.charAt(i)<='9')||(aline.charAt(i)=='.'))
{
tmp=tmp+" ";
}
else tmp=tmp+aline.charAt(i);
if ( aline.charAt(i)=='.')
{
flag=0;
int j;
for(j=i+1;j<aline.length();j++)
tmp=tmp+aline.charAt(j);
}
i=i+1;
}//end of while
aline=tmp;
}//end of if is 0----9
}//end 0f if (st.length()>0)
out.writeBytes(aline);
out.writeBytes("\r\n");
aline=in.readLine() ;
}
System.out.println("System normal Termination by tjy");
in.close();out.close();
in1.close();out1.close();
copy_file.copyfile1("tmp.txt",args[0]);
//fw.close();
}
}
{
public static void main(String args[])
{
DataInputStream is=null;
try
{
is=new DataInputStream (new FileInputStream("firewall.par"));
}
catch(Exception e)
{
System.exit(0);
} try
{
String para[2][100]=null;
while(is.available()!=0)
{
String ch=is.readLine(); for(int i=0;i<ch.length;i++)
{
}
System.out.println(ch);
}
}
catch(IOException e)
{
System.out.println("The FileInputStream() error!");
System.exit(0);
}
}
}
{
File dir=new File(pathName);
if(!dir.exists()) //判断目录是否存在
dir.mkdirs(); //如果目录不存在,则创建目录
java.io.RandomAccessFile rf=new RandomAccessFile(pathName+fileName,"rw");
rf.seek(rf.length());
rf.writeBytes(new String(logInfo.getBytes(),"ISO-8859-1")+"\n"); //支持中文输出到文件,并换行
rf.close();
}
catch(IOException e)
{
e.printStackTrace();
}