50,749
社区成员
发帖
与我相关
我的任务
分享
package text;
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();
}
}
}
}
}
创建的mp3格式或其他格式总是文件损坏求解~