淫秽TAB yin2hui4 TAB淫秽;色情;淫秽网站TAB wang3zhan4 TAB网站
专项TAB zhuan1xiang4 TAB attr。指定用途
但我使用的flashcard应用程序需要这种格式:(字符NEWLINE发音NEWLINE定义)
淫秽
yin2hui4
淫秽;色情;淫秽
网站
wang3zhan4
<计算>网站
专项
zhuan1xiang4
ATTR。指定用途
我只知道一点Java。如何将第一种格式转换为第二种格式?
答案 0 :(得分:2)
显然,我们不想做你的功课。但我们也不想让你陷入困境。
我已经打开了许多东西,下面只是一个看起来像Java的伪代码。你可以从这里开始......
FileReader reader = ... // open the file reader using the input file
FileWriter writer = ...// open a file for writing output
while(the stream doesn't end) { // provide the condition, as must be
String line = ... // read a line from the reader
String character = line.substring(0, line.indexOf("\t")),
pronounciation = line.substring(character.length() -1).substring(line.indexOf("\t", character.length()),
definition = line.substring(line.lastIndexOf("\t")); // Obviously, this isn't accurate.... you need to work around this.
writeLineToFile(character)
writeLineToFile(pronounciation)
writeLineToFile(definition)
}
close the reader and writer
答案 1 :(得分:0)
即使它看起来像练习。但理想情况下你可以这样做。
示例代码
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class Test {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String path = "C:/test.txt";
// TODO Auto-generated method stub
File file = new File(path);
String string = FileUtils.readFileToString(file);
String finalString = string.replaceAll("\t", "\n");
FileUtils.write(file, finalString);
}
}
现在该文件看起来像
淫秽
yin2hui4
obscene; salacious; bawdy
网站
wang3zhan4
website
专项
zhuan1xiang4
attr. earmarked