java ---- 文件读取文件另存为

来源:互联网 发布:运行算法注册机 编辑:程序博客网 时间:2024/05/23 11:40



import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import javax.swing.JFileChooser;public class Main {public static void main(String ar[]){JFileChooser fileChooser =new JFileChooser();fileChooser.showOpenDialog(null);File fl = fileChooser.getSelectedFile();byte b[] =new byte[(int)fl.length()];try {FileInputStream fileinput =new FileInputStream(fl);fileinput.read(b);String string=new String(b);System.out.println(fl.getAbsolutePath());System.out.print(string);fileChooser.showSaveDialog(null);File fout =fileChooser.getSelectedFile();FileOutputStream fileout =new FileOutputStream(fout);fileout.write(b);fileout.close();} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}}



















原创粉丝点击