把文件a.txt复制到指定目录下为a.mp3

Posted 明天的我

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了把文件a.txt复制到指定目录下为a.mp3相关的知识,希望对你有一定的参考价值。

package cn.mldn.demo;
import java.io.*;
public class TestDemo{
 public static void main(String[] args) throws IOException {
  File f1=new File("d:/a.txt");
  InputStream fis=new FileInputStream(f1);
  File f2=new File("d:/a.mp3");
  OutputStream fos=new FileOutputStream(f2);
  if(!f1.exists()){
   System.out.println("目录不存在!");
  }else{
   int temp=0;
   byte data[]=new byte[1024];
   while((temp=fis.read(data))!=-1){
    fos.write(data, 0, temp);
   }
   System.out.println("复制成功!");
  }
  fis.close();
  fos.close();
  
 }
}

以上是关于把文件a.txt复制到指定目录下为a.mp3的主要内容,如果未能解决你的问题,请参考以下文章

PHP文件另存为TXT问题?

bat 如何copy文件到指定位置?

bat怎么批量复制当前目录下若干指定文件到指定目录

python中怎样转到指定目录

centos复制文件夹到指定目录

vc中如何把一个目录包括目录下所有文件,以及子目录复制到指定目录中