51CTO博客开发
定义一个方法 参数: srcFile:被复制的文件 destFile:通过复制得到的新文件public static void copyFile(File srcFile, File destFile) throws IOException{ if(!srcFile.ex
将字符串转换为字节数组,使用当前项目的默认编码:String s = "你好ABC";byte[] b1 = s.getBytes();以“gbk”格式转换字符串:byte[] b2 = s.getBytes("gbk");以“utf-8”格式转换字符串:byte[] b3 = s.getBytes("utf-8");以“utf-16be”格式转换字符串,utf-16be是java的编码格式:by
定位文件,包括文件和文件夹: File file1 = new File("D:\\FileIODemo\\Files"); // 因为要对“\”进行转义,所以要用双斜杠“\\” File file1 = new File("D:/FileIODemo/Files");
Copyright © 2005-2025 51CTO.COM 版权所有 京ICP证060544号