您可以使用 PDF Box 库创建 PDF 文件。您可以按照 Pdf Box 环境教程设置 pdf box 的环境。示例 import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; public class CreatingEmptyPdf { public static void main(String args[]) throws IOException { PDDocument document = new PDDocument(); document.addPage(new PDPage()); document.save("C:/pdfBox/BlankPdf.pdf"); System.out.println("PDF created"); document.close(); } } 输出 PDF created
以下示例展示了通过创建文件过滤器在目录中查找特定文件的方法。以下示例显示所有文件名以“b”开头的文件。示例实时演示 import java.io.*; public class Main { public static void main(String[] args) { File dir = new File("C:"); FilenameFilter filter = new FilenameFilter() { public boolean accept (File dir, String name) { return name.startsWith("b"); } }; String[] children = ... 阅读更多
以下代码按句点和换行符分割给定字符串,如下所示示例 import re s = """Hi. It's nice meeting you. My name is Jason.""" result = re.findall(r'[^\s\.][^\.]+', s) print result 输出 这将给出以下输出 ['Hi', "It's nice meeting you", 'My name is Jason']
println() 通过写入行分隔符字符串来终止当前行。print() 方法只是打印给定的内容。示例实时演示 public class Sample { public static void main(String args[]) { System.out.println("Hello"); System.out.println("how are you"); System.out.print("Hello"); System.out.print("how are you"); } } 输出 Hello how are you Hellohow are you