前几天查了和问了一些关于文件复制的代码,但是运行之后目标根目录下没有生成文件到底怎么回事,因为学的较少所以不知道怎么回事,代码如下:
package text;创建的mp3格式或其他格式总是文件损坏求解~
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
public class Text {
public static void main(String[] args) {
File file = new File("F:\\悦耳模式开启?~/2015新坑/Hacking to the Gate.mp3");
File file1 = new File("G:\\Hacking to the Gate.mp3");
BufferedReader br = null;
PrintStream ps = null;
if (!file1.exists()) {
try {
if (file1.createNewFile()) {
System.out.println("文件创建成功");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
try {
String str;
br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
ps = new PrintStream(file1);
while((str = br.readLine()) != null) {
ps.println(str);
ps.flush();
}
System.out.println("写入成功!");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ps != null) {
ps.close();
}
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
------解决思路----------------------
用字节流读看看