gpt4 book ai didi

Java 输出列表结构不正确

转载 作者:行者123 更新时间:2023-12-01 09:07:42 25 4
gpt4 key购买 nike

我有一个文本文件,其中包含以下内容(部分):

attributes_Accepts_Credit_Cards,
attributes_Accepts_Insurance,
attributes_Ages_Allowed,
attributes_Alcohol,
attributes_Ambience_casual,
attributes_Ambience_classy,
attributes_Ambience_divey,
attributes_Ambience_hipster,
attributes_Ambience_intimate,
attributes_Ambience_romantic,
attributes_Ambience_touristy,
attributes_Ambience_trendy,
attributes_Ambience_upscale,

我正在尝试获得输出,这样我就会得到一个包含以下附加字符的列表:

business['attributes_Accepts_Credit_Cards'],
business['attributes_Accepts_Insurance'],
business['attributes_Ages_Allowed'],

但是目前我的代码以以下方式输出:

business['attributes_Accepts_Credit_Cards'],
business['
attributes_Accepts_Insurance'],
business['
attributes_Ages_Allowed'],
business['
attributes_Alcohol'],
business['
attributes_Ambience_casual'],
business['
attributes_Ambience_classy'],
business['
attributes_Ambience_divey'],
business['
attributes_Ambience_hipster'],
business['
attributes_Ambience_intimate'],

代码:

public class TestScanner {

public static void main(String[] args) throws FileNotFoundException {

Scanner scanner = new Scanner(new File("/list.txt"));
scanner.useDelimiter(",");
while(scanner.hasNextLine()){
System.out.println("business['"+ scanner.next()+"'],");
}
scanner.close();
}

}

最佳答案

您需要将换行符添加到分隔符中:

scanner.useDelimiter(",\n");

关于Java 输出列表结构不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41132810/

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