gpt4 book ai didi

java - 附加带有标题的 java 文件

转载 作者:行者123 更新时间:2023-12-01 21:41:46 27 4
gpt4 key购买 nike

感谢这个社区,我阅读了许多有关如何在 java 中将信息写入 txt 文件的不同方法的教程。但是如果我想要格式化该文件并在文件的每个部分下写入信息怎么办?

我在 myfile.txt 中尝试执行的示例是:

                    list of Apartments
========================

Region===============Country==========Adresse =======PriceMunicipality
writeRegionHere writeCountryHere writeAdressHere writeMunicipalityHere

每次我添加新公寓时,都必须在最后添加信息,这对我来说是一个简单的步骤,我只是不知道如何使用这种格式编写它们

非常感谢

最佳答案

您可以使用它来格式化文本

    private static void printRow(String c0, String c1, String c2, String c3 ) {
System.out.printf("%-20s %-20s %-20s %-20s%n", c0, c1, c2, c3);
}
public static void main(String[] args) {

printRow(" ", "", "List of Appartments", " ");
printRow( "==============", "==============", "==============", "==============");

printRow("Region", "Country", "Adresse", "PriceMunicipilaty");
printRow("==============", "==============", "==============", "==============");
printRow("Adress1", "Adress1" , "Adress1", "Adress2");
}

关于java - 附加带有标题的 java 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36363037/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com