1、文件写入和
如何使用 write() 方法向文件写入内容?
package Practice; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { FileWrite("C:\文档\个人学习资料\IOTest\rainbow.txt"); } /** * @Description: 文件写入 * @Param: [str] * @return: void * @Author: BigData * @Date: 2020/11/5 */ private static void FileWrite(String str) { BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(str)); out.write("文件写入"); out.close(); System.out.println("文件创建成功!"); } catch (IOException e) { e.printStackTrace(); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=62849:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext
ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib
esources.jar;C:Program FilesJavajdk1.8.0_221jrelib
t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2
epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2
epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2
epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorg
eactivestreams
eactive-streams1.0.2
eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2
epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2
epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2
epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2
epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2
epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2
epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2
epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2
epositoryorg
eflections
eflections .9.10
eflections-0.9.10.jar;C:Usersdefaultuser0.m2
epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2
epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2
epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2
epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2
epository
etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2
epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2
epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2
epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2
epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2
epository
etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2
epositoryorgjsonjson20180813json-20180813.jar" Practice.Test
文件创建成功!
Process finished with exit code 0
2、读取文件
如何使用 readLine() 方法来读取文件 test.log 内容?
package Practice; import java.io.*; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String str="C:\文档\个人学习资料\IOTest\rainbow.txt"; readValue(str); } /** * @Description: 读取文件内容 * @Param: [str] * @return: void * @Author: BigData * @Date: 2020/11/5 */ private static void readValue(String str) { try { BufferedReader in=new BufferedReader(new FileReader(str)); String s; while ((s=in.readLine())!=null) { System.out.println(s); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=62944:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext
ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib
esources.jar;C:Program FilesJavajdk1.8.0_221jrelib
t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2
epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2
epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2
epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorg
eactivestreams
eactive-streams1.0.2
eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2
epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2
epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2
epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2
epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2
epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2
epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2
epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2
epositoryorg
eflections
eflections .9.10
eflections-0.9.10.jar;C:Usersdefaultuser0.m2
epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2
epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2
epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2
epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2
epository
etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2
epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2
epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2
epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2
epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2
epository
etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2
epositoryorgjsonjson20180813json-20180813.jar" Practice.Test
文件写入
Process finished with exit code 0
3、删除文件
如何使用 delete() 方法将文件删除?
package Practice; import java.io.*; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String str="C:\文档\个人学习资料\IOTest\rainbow.txt"; delFile(str); } /** * @Description: 删除文件(/+a+tab键) * @Param: [str] * @return: void * @Author: BigData * @Date: 2020/11/5 */ private static void delFile(String str) { try { File file=new File(str); if(file.delete()==true) { System.out.println(file.getName()+"文件已经被删除!"); } else { System.out.println("文集删除失败!"); } } catch (Exception ex) { ex.printStackTrace(); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=63028:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib esources.jar;C:Program FilesJavajdk1.8.0_221jrelib t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2 epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2 epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2 epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorg eactivestreams eactive-streams1.0.2 eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2 epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2 epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2 epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2 epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2 epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2 epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2 epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2 epositoryorg eflections eflections .9.10 eflections-0.9.10.jar;C:Usersdefaultuser0.m2 epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2 epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2 epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2 epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2 epository etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2 epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2 epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2 epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2 epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2 epository etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2 epositoryorgjsonjson20180813json-20180813.jar" Practice.Test rainbow.txt文件已经被删除! Process finished with exit code 0
4、将文件内容复制到另一个文件
package Practice; import java.io.*; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String str="C:\文档\个人学习资料\IOTest\rainbow.txt"; String string="C:\文档\个人学习资料\IOTest\rainbow1.txt"; copyFile(str,string); } /** * @Description: 复制文件内容到另外文件中 * @Param: [string] * @return: void * @Author: BigData * @Date: 2020/11/5 */ private static void copyFile(String string,String string1) { try { BufferedWriter out=new BufferedWriter(new FileWriter(string)); out.write("复制文件"); out.close(); InputStream in=new FileInputStream(new File(string)); OutputStream out1=new FileOutputStream(new File(string1)); byte[] buf=new byte[1024]; int len; while ((len=in.read(buf))>0) { out1.write(buf,0,len); } in.close(); out1.close(); BufferedReader in1=new BufferedReader(new FileReader(string1)); String s; while ((s=in1.readLine())!=null) { System.out.println(s); } in1.close(); } catch (IOException e) { e.printStackTrace(); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=63140:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext
ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib
esources.jar;C:Program FilesJavajdk1.8.0_221jrelib
t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2
epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2
epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2
epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorg
eactivestreams
eactive-streams1.0.2
eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2
epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2
epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2
epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2
epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2
epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2
epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2
epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2
epositoryorg
eflections
eflections .9.10
eflections-0.9.10.jar;C:Usersdefaultuser0.m2
epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2
epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2
epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2
epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2
epository
etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2
epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2
epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2
epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2
epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2
epository
etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2
epositoryorgjsonjson20180813json-20180813.jar" Practice.Test
复制文件
Process finished with exit code 0
5、向文件中追加数据
package Practice; import com.sun.org.glassfish.gmbal.Description; import java.io.*; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String str="C:\文档\个人学习资料\IOTest\rainbow2.txt"; String string="追加的内容"; appendContent(str,string); } /** * @Description:追加内容 * @Param: * @return: * @Author: BigData * @Date: 2020/11/6 */ private static void appendContent(String str,String s) { try { BufferedWriter out=new BufferedWriter(new FileWriter(str)); out.write("原内容--->>>>"); out.close(); //1.注意 out=new BufferedWriter(new FileWriter(str,true)); out.write(s); out.close(); BufferedReader in=new BufferedReader(new FileReader(str)); String string; while ((string=in.readLine())!=null) { System.out.println(string); } } catch (Exception ex) { System.out.println("错误内容:"+ex); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=50466:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib esources.jar;C:Program FilesJavajdk1.8.0_221jrelib t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2 epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2 epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2 epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorg eactivestreams eactive-streams1.0.2 eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2 epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2 epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2 epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2 epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2 epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2 epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2 epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2 epositoryorg eflections eflections .9.10 eflections-0.9.10.jar;C:Usersdefaultuser0.m2 epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2 epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2 epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2 epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2 epository etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2 epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2 epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2 epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2 epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2 epository etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2 epositoryorgjsonjson20180813json-20180813.jar" Practice.Test 原内容--->>>>追加的内容 Process finished with exit code 0
6、创建临时文件
如何使用 File 类的 createTempFile(String prefix, String suffix); 方法在默认临时目录来创建临时文件,参数 prefix 为前缀,suffix 为后缀?
package Practice; import com.sun.org.glassfish.gmbal.Description; import java.io.*; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String path="C:\文档\个人学习资料\IOTest\"; String file="test"; String fmt=".txt"; creatTmpFile(path,file,fmt); } /** * @Description: 根据文件路径,文件名和文件格式来创建临时文件 * @Param: * @return: * @Author: BigData * @Date: 2020/11/9 */ private static void creatTmpFile(String path,String file,String fmt) { File f=null; try { //创建临时文件 f=File.createTempFile(file,fmt,new File(path)); // 输出绝对路径 System.out.println("临时文件绝对路径:"+f.getAbsolutePath()); // 终止后删除临时文件 f.deleteOnExit(); } catch (IOException e) { e.printStackTrace(); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=54225:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext
ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib
esources.jar;C:Program FilesJavajdk1.8.0_221jrelib
t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2
epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2
epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2
epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorg
eactivestreams
eactive-streams1.0.2
eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2
epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2
epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2
epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2
epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2
epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2
epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2
epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2
epositoryorg
eflections
eflections .9.10
eflections-0.9.10.jar;C:Usersdefaultuser0.m2
epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2
epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2
epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2
epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2
epository
etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2
epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2
epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2
epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2
epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2
epository
etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2
epositoryorgjsonjson20180813json-20180813.jar" Practice.Test
临时文件绝对路径:C:文档个人学习资料IOTest est8748305055128945538.txt
Process finished with exit code 0
7、修改文件最后的修改日期
如何使用 File 类的 fileToChange.lastModified() 和 fileToChange setLastModified() 方法来修改文件最后的修改日期?
package Practice; import com.sun.org.glassfish.gmbal.Description; import java.io.*; import java.util.Date; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String path="C:\文档\个人学习资料\IOTest\rainbow.txt"; updateFileTime(path); } /** * @Description: 修改文件的日期 * @Param: * @return: * @Author: BigData * @Date: 2020/11/9 */ private static void updateFileTime(String path) { File file=new File(path); try { file.createNewFile(); Date date=new Date(file.lastModified()); System.out.println(date.toString()); System.out.println(file.setLastModified(System.currentTimeMillis())); date=new Date(file.lastModified()); System.out.println(date.toString()); } catch (IOException e) { e.printStackTrace(); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=54324:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib esources.jar;C:Program FilesJavajdk1.8.0_221jrelib t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2 epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2 epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2 epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorg eactivestreams eactive-streams1.0.2 eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2 epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2 epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2 epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2 epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2 epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2 epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2 epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2 epositoryorg eflections eflections .9.10 eflections-0.9.10.jar;C:Usersdefaultuser0.m2 epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2 epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2 epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2 epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2 epository etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2 epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2 epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2 epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2 epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2 epository etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2 epositoryorgjsonjson20180813json-20180813.jar" Practice.Test Thu Nov 05 17:42:25 CST 2020 true Mon Nov 09 09:40:12 CST 2020 Process finished with exit code 0
8、获取文件大小
如何使用 File 类的 file.exists() 和 file.length() 方法来获取文件大小,以字节计算(1KB=1024字节 )?
package Practice; import com.sun.org.glassfish.gmbal.Description; import java.io.*; import java.util.Date; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String path="C:\文档\个人学习资料\IOTest\rainbow.txt"; System.out.println(path+"的文件大小是:"+getFileSize(path)); } /** * @Description: 获取文件的大小 * @Param: [filename] * @return: long * @Author: BigData * @Date: 2020/11/9 */ public static long getFileSize(String filename) { File file = new File(filename); if (!file.exists() || !file.isFile()) { System.out.println("文件不存在"); return -1; } return file.length(); } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=54409:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib esources.jar;C:Program FilesJavajdk1.8.0_221jrelib t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2 epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2 epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2 epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorg eactivestreams eactive-streams1.0.2 eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2 epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2 epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2 epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2 epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2 epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2 epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2 epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2 epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2 epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2 epositoryorg eflections eflections .9.10 eflections-0.9.10.jar;C:Usersdefaultuser0.m2 epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2 epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2 epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2 epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2 epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2 epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2 epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2 epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2 epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2 epository etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2 epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2 epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2 epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2 epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2 epository etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2 epositoryorgjsonjson20180813json-20180813.jar" Practice.Test C:文档个人学习资料IOTest ainbow.txt的文件大小是:12 Process finished with exit code 0
9、文件重命名
package Practice; import com.sun.org.glassfish.gmbal.Description; import java.io.File; import java.io.IOException; /** * @program: FlinkUdf * @description: IO文件流 * @author: BigData * @create: 2020-11-05 17:18 **/ public class Test { public static void main(String[] args) { String oldName="C:\文档\个人学习资料\IOTest\rainbow.txt"; String newName="C:\文档\个人学习资料\IOTest\rainbowTest.txt"; renameFileName(oldName,newName); } /** * @Description: 重命名文件名 * @Param: * @return: * @Author: BigData * @Date: 2020/11/9 */ public static void renameFileName(String oldName,String newName) { File oldFile=new File(oldName); File newFile=new File(newName); if(newFile.exists()) { try { throw new java.io.IOException("文件已经存在"); } catch (IOException e) { e.printStackTrace(); } } if(oldFile.renameTo(newFile)) { System.out.println(oldName+"重命名为:"+newName); } else { System.out.println("错误命名"); } } }
结果:
"C:Program FilesJavajdk1.8.0_221injava.exe" "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3libidea_rt.jar=54757:C:Program FilesJetBrainsIntelliJ IDEA 2019.3.3in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJavajdk1.8.0_221jrelibcharsets.jar;C:Program FilesJavajdk1.8.0_221jrelibdeploy.jar;C:Program FilesJavajdk1.8.0_221jrelibextaccess-bridge-64.jar;C:Program FilesJavajdk1.8.0_221jrelibextcldrdata.jar;C:Program FilesJavajdk1.8.0_221jrelibextdnsns.jar;C:Program FilesJavajdk1.8.0_221jrelibextjaccess.jar;C:Program FilesJavajdk1.8.0_221jrelibextjfxrt.jar;C:Program FilesJavajdk1.8.0_221jrelibextlocaledata.jar;C:Program FilesJavajdk1.8.0_221jrelibext
ashorn.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunec.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunjce_provider.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunmscapi.jar;C:Program FilesJavajdk1.8.0_221jrelibextsunpkcs11.jar;C:Program FilesJavajdk1.8.0_221jrelibextzipfs.jar;C:Program FilesJavajdk1.8.0_221jrelibjavaws.jar;C:Program FilesJavajdk1.8.0_221jrelibjce.jar;C:Program FilesJavajdk1.8.0_221jrelibjfr.jar;C:Program FilesJavajdk1.8.0_221jrelibjfxswt.jar;C:Program FilesJavajdk1.8.0_221jrelibjsse.jar;C:Program FilesJavajdk1.8.0_221jrelibmanagement-agent.jar;C:Program FilesJavajdk1.8.0_221jrelibplugin.jar;C:Program FilesJavajdk1.8.0_221jrelib
esources.jar;C:Program FilesJavajdk1.8.0_221jrelib
t.jar;C:appFlinkUdf arget est-classes;C:Usersdefaultuser0.m2
epositoryjunitjunit4.11junit-4.11.jar;C:Usersdefaultuser0.m2
epositoryorghamcresthamcrest-core1.3hamcrest-core-1.3.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java-bridge_2.111.11.1flink-table-api-java-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-java1.11.1flink-table-api-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-java1.11.1flink-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-lang33.3.2commons-lang3-3.3.2.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-math33.5commons-math3-3.5.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-runtime_2.111.11.1flink-runtime_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-queryable-state-client-java1.11.1flink-queryable-state-client-java-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-hadoop-fs1.11.1flink-hadoop-fs-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycommons-iocommons-io2.4commons-io-2.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-netty4.1.39.Final-11.0flink-shaded-netty-4.1.39.Final-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-jackson2.10.1-11.0flink-shaded-jackson-2.10.1-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-zookeeper-33.4.14-11.0flink-shaded-zookeeper-3-3.4.14-11.0.jar;C:Usersdefaultuser0.m2
epositorycommons-clicommons-cli1.3.1commons-cli-1.3.1.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-actor_2.112.5.21akka-actor_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeconfig1.3.3config-1.3.3.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-java8-compat_2.11 .7.0scala-java8-compat_2.11-0.7.0.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-stream_2.112.5.21akka-stream_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorg
eactivestreams
eactive-streams1.0.2
eactive-streams-1.0.2.jar;C:Usersdefaultuser0.m2
epositorycom ypesafessl-config-core_2.11 .3.7ssl-config-core_2.11-0.3.7.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-protobuf_2.112.5.21akka-protobuf_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositorycom ypesafeakkaakka-slf4j_2.112.5.21akka-slf4j_2.11-2.5.21.jar;C:Usersdefaultuser0.m2
epositoryorgclappergrizzled-slf4j_2.111.3.2grizzled-slf4j_2.11-1.3.2.jar;C:Usersdefaultuser0.m2
epositorycomgithubscoptscopt_2.113.5.0scopt_2.11-3.5.0.jar;C:Usersdefaultuser0.m2
epositoryorgxerialsnappysnappy-java1.1.4snappy-java-1.1.4.jar;C:Usersdefaultuser0.m2
epositorycom witterchill_2.11 .7.6chill_2.11-0.7.6.jar;C:Usersdefaultuser0.m2
epositorycom witterchill-java .7.6chill-java-0.7.6.jar;C:Usersdefaultuser0.m2
epositoryorglz4lz4-java1.6.0lz4-java-1.6.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-guava18.0-11.0flink-shaded-guava-18.0-11.0.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-java_2.111.11.1flink-streaming-java_2.11-1.11.1-tests.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-api1.7.15slf4j-api-1.7.15.jar;C:Usersdefaultuser0.m2
epositorycomgooglecodefindbugsjsr3051.3.9jsr305-1.3.9.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkforce-shading1.11.1force-shading-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-planner-blink_2.111.11.1flink-table-planner-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala_2.111.11.1flink-table-api-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-api-scala-bridge_2.111.11.1flink-table-api-scala-bridge_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-runtime-blink_2.111.11.1flink-table-runtime-blink_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninojanino3.0.9janino-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgcodehausjaninocommons-compiler3.0.9commons-compiler-3.0.9.jar;C:Usersdefaultuser0.m2
epositoryorgapachecalciteavaticaavatica-core1.16.0avatica-core-1.16.0.jar;C:Usersdefaultuser0.m2
epositoryorg
eflections
eflections .9.10
eflections-0.9.10.jar;C:Usersdefaultuser0.m2
epositoryorgjavassistjavassist3.19.0-GAjavassist-3.19.0-GA.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-streaming-scala_2.111.11.1flink-streaming-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-scala_2.111.11.1flink-scala_2.11-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-reflect2.11.12scala-reflect-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-library2.11.12scala-library-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langscala-compiler2.11.12scala-compiler-2.11.12.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-xml_2.111.0.5scala-xml_2.11-1.0.5.jar;C:Usersdefaultuser0.m2
epositoryorgscala-langmodulesscala-parser-combinators_2.111.0.4scala-parser-combinators_2.11-1.0.4.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-table-common1.11.1flink-table-common-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-core1.11.1flink-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-annotations1.11.1flink-annotations-1.11.1.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-metrics-core1.11.1flink-metrics-core-1.11.1.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwarekryokryo2.24.0kryo-2.24.0.jar;C:Usersdefaultuser0.m2
epositorycomesotericsoftwareminlogminlog1.2minlog-1.2.jar;C:Usersdefaultuser0.m2
epositoryorgobjenesisobjenesis2.1objenesis-2.1.jar;C:Usersdefaultuser0.m2
epositoryorgapachecommonscommons-compress1.20commons-compress-1.20.jar;C:Usersdefaultuser0.m2
epositoryorgapacheflinkflink-shaded-asm-77.1-11.0flink-shaded-asm-7-7.1-11.0.jar;C:Usersdefaultuser0.m2
epositorycomalibabafastjson1.2.73fastjson-1.2.73.jar;C:Usersdefaultuser0.m2
epositoryorgslf4jslf4j-log4j121.7.7slf4j-log4j12-1.7.7.jar;C:Usersdefaultuser0.m2
epositorylog4jlog4j1.2.17log4j-1.2.17.jar;C:Usersdefaultuser0.m2
epository
etsfjson-libjson-lib2.4json-lib-2.4-jdk15.jar;C:Usersdefaultuser0.m2
epositorycommons-beanutilscommons-beanutils1.8.0commons-beanutils-1.8.0.jar;C:Usersdefaultuser0.m2
epositorycommons-collectionscommons-collections3.2.1commons-collections-3.2.1.jar;C:Usersdefaultuser0.m2
epositorycommons-langcommons-lang2.5commons-lang-2.5.jar;C:Usersdefaultuser0.m2
epositorycommons-loggingcommons-logging1.1.1commons-logging-1.1.1.jar;C:Usersdefaultuser0.m2
epository
etsfezmorphezmorph1.0.6ezmorph-1.0.6.jar;C:Usersdefaultuser0.m2
epositoryorgjsonjson20180813json-20180813.jar" Practice.Test
C:文档个人学习资料IOTest
ainbow.txt重命名为:C:文档个人学习资料IOTest
ainbowTest.txt
Process finished with exit code 0
10、设置文件只读
使用 File 类的 file.setReadOnly() 和 file.canWrite() 方法来设置文件只读
import java.io.File; public class Main { public static void main(String[] args) { File file = new File("C:/java.txt"); System.out.println(file.setReadOnly()); System.out.println(file.canWrite()); } }
结果:
true false
11、检测文件是否存在
使用 File 类的 file.exists() 方法来检测文件是否存在
import java.io.File; public class Main { public static void main(String[] args) { File file = new File("C:/java.txt"); System.out.println(file.exists()); } }
12、在指定目录中创建文件
import java.io.File; public class Main { public static void main(String[] args) throws Exception { File file = null; File dir = new File("C:/"); file = File.createTempFile ("JavaTemp", ".javatemp", dir); System.out.println(file.getPath()); }
结果:
C:JavaTemp37056.javatemp
13、获取文件修改时间
import java.io.File; import java.util.Date; public class Main { public static void main(String[] args) { File file = new File("Main.java"); Long lastModified = file.lastModified(); Date date = new Date(lastModified); System.out.println(date); } }
结果:
Thu Apr 09 09:40:19 CST 2015
14、创建文件
import java.io.File; import java.io.IOException; public class Main { public static void main(String[] args) { try{ File file = new File("C:/myfile.txt"); if(file.createNewFile()) System.out.println("文件创建成功!"); else System.out.println("出错了,该文件已经存在。"); } catch(IOException ioe) { ioe.printStackTrace(); } } }
结果:
文件创建成功!
15、文件路径比较
使用 File 类的 filename.compareTo (another filename) 方法来比较两个文件路径是否在同一个目录下:
import java.io.File; public class Main { public static void main(String[] args) { File file1 = new File("C:/File/demo1.txt"); File file2 = new File("C:/java/demo1.txt"); if(file1.compareTo(file2) == 0) { System.out.println("文件路径一致!"); } else { System.out.println("文件路径不一致!"); } } }
结果:
文件路径不一致!