【萌新求教】关于文件复制(非.txt和.dat文件)的一点疑问

wowreq wowreq 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
前几天查了和问了一些关于文件复制的代码,但是运行之后目标根目录下没有生成文件到底怎么回事,因为学的较少所以不知道怎么回事,代码如下:
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格式或其他格式总是文件损坏求解~
...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部
wowreq
Java 51,407 成员 86,130 内容