Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何写入ArrayList的项<;阿拉>;在一个带有JAVA的文件中?_Java_Arraylist_Fileoutputstream_Objectoutputstream - Fatal编程技术网

如何写入ArrayList的项<;阿拉>;在一个带有JAVA的文件中?

如何写入ArrayList的项<;阿拉>;在一个带有JAVA的文件中?,java,arraylist,fileoutputstream,objectoutputstream,Java,Arraylist,Fileoutputstream,Objectoutputstream,我读取了一个包含单词列表及其标记的文本文件,并将它们作为ArrayList放入包装ArrayList(ArrayList)中 [[1,that,that,DT,DT],[2,table,table,table,NN,NN] 现在,我想以如下相同的格式在文本文件中写入: 1 that that that DT DT 2 table table table NN NN 上面的每一行都是一个包含6列的ArrayList 下面的代码返回一个

我读取了一个包含单词列表及其标记的文本文件,并将它们作为ArrayList放入包装ArrayList(ArrayList)中

[[1,that,that,DT,DT],[2,table,table,table,NN,NN]

现在,我想以如下相同的格式在文本文件中写入:

1    that    that     that    DT    DT  
2    table   table    table   NN    NN
上面的每一行都是一个包含6列的ArrayList

下面的代码返回一个带有Ԁ在里面

public void setPPOSOfWordInDevelopmentList(ArrayList<ArrayList> trainingList){
try{
    FileOutputStream streamFile = new FileOutputStream("developmentFile.txt");
    ObjectOutputStream streamFileWriter = new ObjectOutputStream(streamFile);
for(ArrayList word: developmentWordsList){
    String inputWord = (String)word.get(1);
    extractTag(inputWord,trainingList);
    String extractedPPOSofWord =(String)findMaxTag().get(1);
    word.set(5, extractedPPOSofWord);

}
streamFileWriter.close();
System.out.println(developmentWordsList);
}
catch(Exception e){
    System.out.println("Something went wrong, check the code");
}
}
public void setopsofwordindevelopmentlist(数组列表培训列表){
试一试{
FileOutputStreamFile=新的FileOutputStream(“developmentFile.txt”);
ObjectOutputStream streamFileWriter=新的ObjectOutputStream(streamFile);
for(ArrayList单词:developmentWordsList){
字符串inputWord=(字符串)word.get(1);
提取标签(输入字、培训列表);
String extractedPPOSofWord=(String)findMaxTag().get(1);
单词集(5,提取单词);
}
streamFileWriter.close();
System.out.println(开发字列表);
}
捕获(例外e){
System.out.println(“出错,请检查代码”);
}
}

此代码与其他一些代码结合在一起,因此更改函数返回的对象的格式并不容易。

您想要的内容听起来像是标准文件。这将使您直接了解如何解析此类内容。我强烈建议您按照CSV文件进行重构,而不是使用ObjectInput/OutputStreams。它将更易于维护,并且您可以在调试时使用Excel和OpenOffice Calc等工具查看您的文件。

您想要的文件听起来非常像标准文件。这将使您直接了解如何解析此类内容。我强烈建议您按照CSV文件进行重构,而不是使用ObjectInput/OutputStreams。它将更易于维护,并且您可以在调试时使用Excel和OpenOffice Calc等工具查看您的文件。

您想要的文件听起来非常像标准文件。这将使您直接了解如何解析此类内容。我强烈建议您按照CSV文件进行重构,而不是使用ObjectInput/OutputStreams。它将更易于维护,并且您可以在调试时使用Excel和OpenOffice Calc等工具查看您的文件。

您想要的文件听起来非常像标准文件。这将使您直接了解如何解析此类内容。我强烈建议您按照CSV文件进行重构,而不是使用ObjectInput/OutputStreams。它将更易于维护,并且您可以在调试时使用Excel和OpenOffice Calc等工具查看文件。

如果您想编写简单的文本文件,最好使用BufferedWriter。对于内容,如果太长,可以在StringBuffer或StringBuilder中格式化。在这篇文章中,我回答了一个与您试图制作的格式有关的问题。但是您需要根据您的格式和使用包装数组的逻辑来调整它

我认为,循环或“enhanced for”语句应该像这样使用:

for (ArrayList<String> innerArray: wrapperArray) {
    for (String word : innerArray) {
        //Adapt to your required format using a StringBuilder
    }
}
//Here at the end save the content of your StringBuilder or StringBuffer using the BufferedWriter.
for(ArrayList innerArray:wrapperArray){
for(字符串字:innerArray){
//使用StringBuilder调整您所需的格式
}
}
//最后,使用BufferedWriter保存StringBuilder或StringBuffer的内容。

希望你能对如何实现这一目标有一个想法。最好的祝愿:)

如果您想编写一个简单的文本文件,最好使用BufferedWriter。对于内容,如果太长,可以在StringBuffer或StringBuilder中格式化。在这篇文章中,我回答了一个与您试图制作的格式有关的问题。但是您需要根据您的格式和使用包装数组的逻辑来调整它

我认为,循环或“enhanced for”语句应该像这样使用:

for (ArrayList<String> innerArray: wrapperArray) {
    for (String word : innerArray) {
        //Adapt to your required format using a StringBuilder
    }
}
//Here at the end save the content of your StringBuilder or StringBuffer using the BufferedWriter.
for(ArrayList innerArray:wrapperArray){
for(字符串字:innerArray){
//使用StringBuilder调整您所需的格式
}
}
//最后,使用BufferedWriter保存StringBuilder或StringBuffer的内容。

希望你能对如何实现这一目标有一个想法。最好的祝愿:)

如果您想编写一个简单的文本文件,最好使用BufferedWriter。对于内容,如果太长,可以在StringBuffer或StringBuilder中格式化。在这篇文章中,我回答了一个与您试图制作的格式有关的问题。但是您需要根据您的格式和使用包装数组的逻辑来调整它

我认为,循环或“enhanced for”语句应该像这样使用:

for (ArrayList<String> innerArray: wrapperArray) {
    for (String word : innerArray) {
        //Adapt to your required format using a StringBuilder
    }
}
//Here at the end save the content of your StringBuilder or StringBuffer using the BufferedWriter.
for(ArrayList innerArray:wrapperArray){
for(字符串字:innerArray){
//使用StringBuilder调整您所需的格式
}
}
//最后,使用BufferedWriter保存StringBuilder或StringBuffer的内容。

希望你能对如何实现这一目标有一个想法。最好的祝愿:)

如果您想编写一个简单的文本文件,最好使用BufferedWriter。对于内容,如果太长,可以在StringBuffer或StringBuilder中格式化。在这篇文章中,我回答了一个与您试图制作的格式有关的问题。但是您需要根据您的格式和使用包装数组的逻辑来调整它

我认为,循环或“enhanced for”语句应该像这样使用:

for (ArrayList<String> innerArray: wrapperArray) {
    for (String word : innerArray) {
        //Adapt to your required format using a StringBuilder
    }
}
//Here at the end save the content of your StringBuilder or StringBuffer using the BufferedWriter.
for(ArrayList innerArray:wrapperArray){
for(字符串字:innerArray){
//使用StringBuilder调整您所需的格式
}
}
//最后,使用BufferedWriter保存StringBuilder或StringBuffer的内容。
希望你能对如何实现这一目标有一个想法。致以最诚挚的问候:)

如果您是正确的