当前目录下,若无新建文本文档.txt,请创建一个空白问句文档。

2026-04-16 14:022阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计182个文字,预计阅读时间需要1分钟。

当前目录下,若无新建文本文档.txt,请创建一个空白问句文档。

在当前路径下新建文本文档:newTextDocument.txt

import java.io.*; import java.util.logging.Level; import java.util.logging.Logger;

当前目录下,若无新建文本文档.txt,请创建一个空白问句文档。

public class createEmptyFiles { public static void main(String[] args) { String fileName=newTextDocument.txt; File file=new File(fileName); try { if (file.createNewFile()) { System.out.println(文件创建成功: + fileName); } else { System.out.println(文件已存在: + fileName); } } catch (IOException ex) { Logger.getLogger(createEmptyFiles.class.getName()).log(Level.SEVERE, null, ex); } } }

在当前路径新建文本文档.java

import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; public class createEmptyFiles { public static void main(String[] args) { String fileName = "新建文本文档.txt"; File file = new File(fileName); int counter = 2; while(file.exists()){ fileName = "新建文本文档" + "(" + counter + ")" + ".txt"; file = new File(fileName); counter++; } try { file.createNewFile(); System.out.println("创建成功"); } catch (IOException ex) { Logger.getLogger(createEmptyFiles.class.getName()).log(Level.SEVERE, null, ex); } } }

本文共计182个文字,预计阅读时间需要1分钟。

当前目录下,若无新建文本文档.txt,请创建一个空白问句文档。

在当前路径下新建文本文档:newTextDocument.txt

import java.io.*; import java.util.logging.Level; import java.util.logging.Logger;

当前目录下,若无新建文本文档.txt,请创建一个空白问句文档。

public class createEmptyFiles { public static void main(String[] args) { String fileName=newTextDocument.txt; File file=new File(fileName); try { if (file.createNewFile()) { System.out.println(文件创建成功: + fileName); } else { System.out.println(文件已存在: + fileName); } } catch (IOException ex) { Logger.getLogger(createEmptyFiles.class.getName()).log(Level.SEVERE, null, ex); } } }

在当前路径新建文本文档.java

import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; public class createEmptyFiles { public static void main(String[] args) { String fileName = "新建文本文档.txt"; File file = new File(fileName); int counter = 2; while(file.exists()){ fileName = "新建文本文档" + "(" + counter + ")" + ".txt"; file = new File(fileName); counter++; } try { file.createNewFile(); System.out.println("创建成功"); } catch (IOException ex) { Logger.getLogger(createEmptyFiles.class.getName()).log(Level.SEVERE, null, ex); } } }