格式化输出文件 [英] Formatting output file
问题描述
大家好,
我是java编程的新手。我想编写一个程序,将输入文件转换为输出文件,其中的字段用逗号分隔。以下是样本输入:
12345某些词某些词某些词
21345 somewords somewords somewords
以下是我想要的输出:
12345,某些词,某些词,somewords
21345,某些词,某些词,某些词
请帮我写这个程序。我非常感谢你的帮助。
Hi all,
I am very new to java programming. I want to write a program that turn an input file into the output file with fields separated by comma. Here is the sample input:
12345 somewords somewords somewords
21345 somewords somewords somewords
Below is the output I want to have:
12345,somewords,somewords,"somewords
21345,somewords,somewords,somewords
Please help me write this program. I would very much appreciate your help.
推荐答案
大家好,
我是java编程的新手。我想编写一个程序,将输入文件转换为输出文件,其中的字段用逗号分隔。以下是样本输入:
12345某些词某些词某些词
21345 somewords somewords somewords
以下是我想要的输出:
12345,某些词,某些词,somewords
21345,某些词,某些词,某些词
请帮我写这个程序。我非常感谢你的帮助。
Hi all,
I am very new to java programming. I want to write a program that turn an input file into the output file with fields separated by comma. Here is the sample input:
12345 somewords somewords somewords
21345 somewords somewords somewords
Below is the output I want to have:
12345,somewords,somewords,"somewords
21345,somewords,somewords,somewords
Please help me write this program. I would very much appreciate your help.
你知道如何使用FileReader读取文件。
还考虑将整个文件读入StringBuider对象然后替换所有文件带逗号的空格。您可能需要在结束时进行一些内务管理。
Do you know how to read a file using FileReader then.
Also consider reading the whole file into a StringBuider object and then replacing all spaces with commas. You may need to do a bit of housekeeping at the end.
您在读取文件时是否可以使用字符串标记符,然后只输出token1,token2,token3,token4?
Could you use string tokenizer when reading in the file, then just output token1,token2,token3,token4?
您是否知道如何使用FileReader读取文件。
还考虑将整个文件读入StringBuider对象并然后用逗号替换所有空格。你可能需要在最后做一些家务。
Do you know how to read a file using FileReader then.
Also consider reading the whole file into a StringBuider object and then replacing all spaces with commas. You may need to do a bit of housekeeping at the end.
嗨管理员,
Hi Admin,
I know how to read the file using FileReader/BufferedReader. But I have the problem with the logic of how to add comma and replace the whitespaces between each fields. Please if you can write a simple code so that I can learn from it. I appreciate it very much.
这篇关于格式化输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!