当前位置: 首页 > news >正文

网站呼叫中心 建设工期吴川房产网

网站呼叫中心 建设工期,吴川房产网,网站建设需要注意哪些关键细节,长春今天最新通告目录 文件写入读取文件内容删除文件复制文件向文件中追加数据创建临时文件文件/目录最后的修改日期获取文件大小文件重命名设置文件只读检测文件是否存在创建文件文件路径比较递归创建目录删除目录判断目录是否为空判断文件是否隐藏获取目录大小在指定目录中查找文件获取文件的… 目录 文件写入读取文件内容删除文件复制文件向文件中追加数据创建临时文件文件/目录最后的修改日期获取文件大小文件重命名设置文件只读检测文件是否存在创建文件文件路径比较递归创建目录删除目录判断目录是否为空判断文件是否隐藏获取目录大小在指定目录中查找文件获取文件的上级目录遍历目录结构遍历指定目录下的所有目录输出指定目录下的所有文件在指定目录中查找匹配文件查看系统根目录查看当前工作目录 文件写入 package com.example.demo;import org.junit.Test;import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException;public class FileTests {Testpublic void testWriteFile() throws IOException {BufferedWriter writer new BufferedWriter(new FileWriter(demo.txt));writer.write(你好世界);writer.close();} } 查看写入结果 $ cat demo.txt 你好世界读取文件内容 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testReadFile() throws IOException {BufferedReader reader new BufferedReader(new FileReader(demo.txt));String line null;while ((line reader.readLine()) ! null) {System.out.println(line);// 你好世界}} } 删除文件 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testDeleteFile() throws IOException {File file new File(demo.txt);boolean isDeleted file.delete();} } 复制文件 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testCopyFile() throws IOException {InputStream input new FileInputStream(new File(source.txt));OutputStream output new FileOutputStream(new File(target.txt));byte[] buf new byte[1024];int len 0;while ((len input.read(buf)) 0) {output.write(buf, 0, len);}input.close();output.close();} } 向文件中追加数据 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testAppendFile() throws IOException {BufferedWriter writer new BufferedWriter(new FileWriter(demo.txt, true));writer.write(Hello World! System.lineSeparator());writer.close();} } 创建临时文件 方法签名 // prefix 前缀 // suffix 后缀 // directory 目录需要提前创建好public static File createTempFile(String prefix, String suffix, File directory)public static File createTempFile(String prefix, String suffix)package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testTempFile() throws IOException {File temp File.createTempFile(temp_, .txt, new File(temp));File absoluteFile temp.getAbsoluteFile();System.out.println(absoluteFile);BufferedWriter writer new BufferedWriter(new FileWriter(temp));writer.write(Hello World! System.lineSeparator());writer.close();} } $ cat temp/temp_4469794763475912115.txtHello World!文件/目录最后的修改日期 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testLastModifiedFile() throws IOException {File file new File(demo.txt);file.createNewFile();// 获取最后修改时间long lastModified file.lastModified();System.out.println(lastModified);// 1696666928606// 修改文件最后的修改日期file.setLastModified(System.currentTimeMillis());System.out.println(file.lastModified());// 1696667018522} } 获取文件大小 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testGetFileSize() throws IOException {File file new File(demo.txt);long length file.length();System.out.println(length);// 434} } 文件重命名 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testRenameFile() throws IOException {File file new File(demo.txt);File newFile new File(newDemo.txt);boolean ret file.renameTo(newFile);} } 设置文件只读 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testReadOnlyFile() {File file new File(demo.txt);System.out.println(file.setReadOnly()); // trueSystem.out.println(file.canWrite()); // false} } 检测文件是否存在 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testFileExists() {File file new File(demo.txt);System.out.println(file.exists()); // true} } 创建文件 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testCreateFile() throws IOException {File file new File(demo.txt);System.out.println(file.createNewFile()); // true} } 文件路径比较 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testCompareFile() throws IOException {File file1 new File(demo1.txt);File file2 new File(demo2.txt);System.out.println(file1.compareTo(file2)); // -1} } 递归创建目录 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testMKDirs() throws IOException {File file new File(./temp/demo);boolean result file.mkdirs();System.out.println(result); // true} } 删除目录 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {public static boolean deleteDir(File dir) {// 递归删除目录中的文件if (dir.isDirectory()) {for (File file : dir.listFiles()) {boolean success deleteDir(file);if (!success) {return false;}}}return dir.delete();}Testpublic void testDeleteDirectory() {File file new File(./temp);boolean result deleteDir(file);System.out.println(result); // true} } 判断目录是否为空 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {public static boolean isEmptyDirectory(File dir) {if(!dir.isDirectory()){throw new RuntimeException(Not a Directory);}return dir.list().length 0;}Testpublic void testEmptyDirectory() {File file new File(./temp);boolean result isEmptyDirectory(file);System.out.println(result); // true} } 判断文件是否隐藏 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testHiddenFile() {File file new File(./temp);boolean result file.isHidden();System.out.println(result); // false} } 获取目录大小 依赖 !-- https://mvnrepository.com/artifact/commons-io/commons-io -- dependencygroupIdcommons-io/groupIdartifactIdcommons-io/artifactIdversion2.11.0/version /dependencypackage com.example.demo;import org.apache.commons.io.FileUtils; import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testDirectorySize() {File file new File(./temp);long sizeOfDirectory FileUtils.sizeOfDirectory(file);System.out.println(sizeOfDirectory); // false} } 在指定目录中查找文件 package com.example.demo;import org.junit.Test;import java.io.*;public class FileTests {Testpublic void testFindFileFromDirectory() {File file new File(./temp);String[] list file.list();for (String filename : list) {System.out.println(filename);}} } 获取文件的上级目录 package com.example.demo;import org.junit.Test;import java.io.File;public class FileTests {Testpublic void testParent() {File file new File(/temp/demo.txt);String parent file.getParent();System.out.println(parent);// /temp} } 遍历目录结构 package com.example.demo;import org.junit.Test;import java.io.File;public class FileTests {public static void showTree(int indent, File file) {// 缩进for (int i 0; i indent; i) {System.out.print(-);}System.out.println(file.getName());if(file.isDirectory()){for (File f : file.listFiles()) {showTree(indent 4, f);}}}Testpublic void testShowTree() {showTree(0, new File(./temp));} } 打印结果 temp ----demo --------demo1.txt ----demo.txt遍历指定目录下的所有目录 package com.example.demo;import org.junit.Test;import java.io.File; import java.io.FileFilter;public class FileTests {Testpublic void testFileFilter() {File file new File(./temp);FileFilter fileFilter new FileFilter(){Overridepublic boolean accept(File pathname) {return pathname.isDirectory();}};File[] files file.listFiles(fileFilter);for (File f : files) {System.out.println(f);}} } 输出指定目录下的所有文件 package com.example.demo;import org.junit.Test;import java.io.File; import java.io.FileFilter;public class FileTests {Testpublic void testListFiles() {File file new File(./temp);File[] files file.listFiles();for (File f : files) {System.out.println(f);}} } 在指定目录中查找匹配文件 package com.example.demo;import org.junit.Test;import java.io.File; import java.io.FileFilter; import java.io.FilenameFilter;public class FileTests {Testpublic void testListFiles() {File file new File(./temp);FilenameFilter filter new FilenameFilter(){Overridepublic boolean accept(File dir, String name) {return name.endsWith(.txt);}};File[] files file.listFiles(filter);for (File f : files) {System.out.println(f);}} } 查看系统根目录 package com.example.demo;import org.junit.Test;import java.io.File;public class FileTests {Testpublic void testListFiles() {File[] roots File.listRoots();for (File f : roots) {System.out.println(f);}// /} } 查看当前工作目录 package com.example.demo;import org.junit.Test;public class FileTests {Testpublic void testCurrentDirectory() {String currentDir System.getProperty(user.dir);System.out.println(currentDir);} }参考 https://www.nowcoder.com/tutorial/10001/d7671778e69f4fd2b66c6209b4bce9a4
http://www.yutouwan.com/news/474812/

相关文章:

  • 医院网站cms三金网手机网站
  • 长沙做旅游网站公司网页设计公司宣传
  • 营销网站 深圳保险公司网站
  • 扬州 网站建设企业网站关联优化
  • 设计素材网站推荐pin重庆网络公司网站建设
  • 网站建设预算申请表视频拍摄及制作培训
  • 初中做网站的软件网站建设费用 知乎
  • 音乐网站怎么做无线增值业务wordpress微信分享二维码生成
  • 外国优秀网站设计wordpress 站外调用
  • 绍兴网站快速排名优化网站推广策划案关键词
  • 网站模板 带数据库本地用织梦做网站
  • 怎样申请网站空间上海市杨浦区建设小学网站
  • 企业网站建设和运营风景旅游网页制作素材
  • 免费看舆情网站嘉兴手机网站
  • 论网站建设情况网站开发查询
  • 国内做性视频网站长春做公司网站的
  • 织梦做仿站时 为何会发生本地地址跳转网站地址安徽网站建设外贸
  • 济南住建网站vs做网站案例
  • 可以直接进入网站的正能量照片wordpress调用文章字数
  • 中英企业网站视频网站用什么做的好处
  • 商城网站解决方案1000元做网站
  • 聊城网站建设工作室网上挣钱正规渠道
  • 搭建一个影视网站青岛的网站建设
  • 连锁加盟网站制作阿里云服务器做盗版视频网站
  • 织梦网站更改网站的导航青岛网站关键词
  • 计算机应用技术毕业设计seo优化网站
  • 自己的网站怎么做关键词优化镇江网友之家百姓话题
  • 企业信息网页模板淄博优化网站
  • 网站免费做招生宣传网站,商城,app+建设
  • 做旅游网站的目的网站设计原型图怎么做