Java: File
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import javafx.application.Application; //https://gluonhq.com/products/javafx/ https://github.com/openjdk/jfx import javafx.fxml.FXMLLoader; //https://gluonhq.com/products/javafx/ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.*; import java.nio.file.Files; import java.nio.file.Files.*; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Scanner; import java.util.NoSuchElementException; import java.lang.IllegalStateException; Scanner input= new Scanner(System.in); System.out.printf( "Enter file or directory name:" ); Path path=Paths.get( "D:\\书籍资料\\java\\JavaHowToProgram11e_EarlyObjects-master\\examples" ); if (Files.exists(path)) { System.out.println( "FileName:" +path.getFileName()); if (Files.isDirectory((path))) { try { DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path); for (Path p : directoryStream) { System.out.println(p.toString()); } } catch (IOException exception) { exception.printStackTrace(); } } } /**/ try (Scanner duinput= new Scanner(Paths.get( "clients.txt" ))) { System.out.printf( "%-10s%-12s%-12s%10s%n" , "Account" , "First Name" , "Last Name" , "Balance" ); while (duinput.hasNext()) { // System.out.printf(""+ System.out.printf( "%-10d%-12s%-12s%10.2f%n" , duinput.nextInt(), duinput.next(), duinput.next(), duinput.nextDouble()); //System.out.printf("geovindu"); } } catch (IOException|NoSuchElementException|IllegalStateException exception) { exception.printStackTrace(); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | //写文件 String dufileName= "geovin.txt" ; String value = "Hello,涂聚文,你好吗" ; try { FileOutputStream fos = new FileOutputStream(dufileName); DataOutputStream outStream = new DataOutputStream( new BufferedOutputStream(fos)); outStream.writeUTF(value); outStream.close(); // verify the results String result; FileInputStream fis = new FileInputStream(dufileName); DataInputStream reader = new DataInputStream(fis); result = reader.readUTF(); reader.close(); } catch (IOException exception) { exception.printStackTrace(); } //写文件 Scanner geovinduinput = new Scanner(System.in); System.out.printf( "%s%n%s%n? " , "Enter account number, first name, last name and balance." , "Enter end-of-file indicator to end input." ); try (Formatter output = new Formatter( "geovindu.txt" )) { while (geovinduinput.hasNext()) { // try { output.format( "%d %s %s %.2f%n" , geovinduinput.nextInt(), geovinduinput.next(), geovinduinput.next(), geovinduinput.nextDouble()); } catch (NoSuchElementException elementException) { System.err.println( "Invalid input. Please try again." ); geovinduinput.nextLine(); // } System.out.print( "? 请输入下一行:" ); } } catch (SecurityException | FileNotFoundException | FormatterClosedException e) { e.printStackTrace(); System.exit( 1 ); // } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //写文件 String dufileName= "geovin1.txt" ; String value = "Hello,涂聚文,你好吗" ; StringBuilder builder= new StringBuilder(); builder.indexOf(value); builder.indexOf( "geovindu" ); try { FileOutputStream fos = new FileOutputStream(dufileName); DataOutputStream outStream = new DataOutputStream( new BufferedOutputStream(fos)); outStream.writeUTF(builder.toString()); outStream.close(); // verify the results String result; FileInputStream fis = new FileInputStream(dufileName); DataInputStream reader = new DataInputStream(fis); result = reader.readUTF(); reader.close(); } catch (IOException exception) { exception.printStackTrace(); } |
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
2016-02-19 csharp:正则表达式采集网页数据