使用字节缓冲流和数组来复制一个东西
| import java.io.*; |
| |
| public class test1 { |
| public static void main(String[] args) throws Exception { |
| |
| long start = System.currentTimeMillis(); |
| String path1 = "/Users/mima000000/Desktop/1.jpeg"; |
| String path2 = "/Users/mima000000/Desktop/2.jpeg"; |
| BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(path1)); |
| BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(path2)); |
| int len; |
| byte[] bytes = new byte[1024]; |
| while ((len=bufferedInputStream.read(bytes))!=-1){ |
| bufferedOutputStream.write(bytes,0,len); |
| } |
| bufferedOutputStream.close(); |
| bufferedInputStream.close(); |
| |
| } |
| } |
| |
转换流
| import com.sun.xml.internal.fastinfoset.util.ValueArrayResourceException; |
| import sun.nio.cs.ext.GBK; |
| |
| import java.io.*; |
| |
| public class test1 { |
| public static void main(String[] args) throws Exception { |
| String path = "/Users/mima000000/Desktop/1.txt"; |
| InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(path), "GBK"); |
| int read; |
| while ((read=inputStreamReader.read())!=-1){ |
| System.out.println((char)read); |
| } |
| inputStreamReader.close(); |
| |
| } |
| } |
| |
转换文件的编码,读取一个gbk 文件,保存为utf-8
| import com.sun.xml.internal.fastinfoset.util.ValueArrayResourceException; |
| import sun.nio.cs.ext.GBK; |
| |
| import java.io.*; |
| |
| public class test1 { |
| public static void main(String[] args) throws Exception { |
| String path = "/Users/mima000000/Desktop/1.txt"; |
| String path2 = "/Users/mima000000/Desktop/2.txt"; |
| InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(path), "GBK"); |
| OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(path2) ,"UTF-8"); |
| int len; |
| char[] temp = new char[1024]; |
| while ((len=inputStreamReader.read(temp))!=-1){ |
| outputStreamWriter.write(temp,0,len); |
| } |
| outputStreamWriter.close(); |
| inputStreamReader.close(); |
| |
| } |
| } |
| |
我对任何唾手而得,快速,出自本能,即兴,含混的事物没有信心。我相信缓慢,平和,细水长流的力量,踏实,冷静。我不相信缺乏自律精神和不自我建设,不努力,可以得到个人或集体的解放。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步