Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.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
Java 为什么我的数组只包含一个]?_Java_Arrays_String - Fatal编程技术网

Java 为什么我的数组只包含一个]?

Java 为什么我的数组只包含一个]?,java,arrays,string,Java,Arrays,String,所以,我正在研究一个程序,它从一个文本区域获取用户的输入,然后将其写入一个文件PSandE.txt。从该文件读取时,第一次它工作正常,所有内容都正确显示,但第二次,除了数组的第一个索引之外,所有内容都不显示,即使在文本区域中没有编辑任何文本 这是我写入文件时的代码: strTextArray = c1notesArea.getText().split("\n"); writer.print("c1Notes: "); for (String strTextTemp : strTextArray)

所以,我正在研究一个程序,它从一个文本区域获取用户的输入,然后将其写入一个文件PSandE.txt。从该文件读取时,第一次它工作正常,所有内容都正确显示,但第二次,除了数组的第一个索引之外,所有内容都不显示,即使在文本区域中没有编辑任何文本

这是我写入文件时的代码:

strTextArray = c1notesArea.getText().split("\n");
writer.print("c1Notes: ");
for (String strTextTemp : strTextArray) {
    writer.print(strTextTemp + "xXenterXx");
}
writer.println(""); writer.println("");
请注意,xXenterXx只是我在将其重新写入文本区域时用来保留格式的东西

但当我从文件中读取时,这是我的代码:

strText = reader.nextLine().substring(9);
strTemp = strText.replace("xXenterXx", newLine);
c1notesArea.setText(strTemp);
.replace是将用户输入的格式替换回文本区域

所以,第一次文本区域中的文本就是这样

Test

Test

Test
当框架再次打开时,这就是输出

Test

Test

Test
我对TextArea没有做任何更改,第二次的输出是:

Test
就这样。我认为这与我使用的阵列有关,因为当我使用

System.out.println(Arrays.toString(strTextArray));
第一次,输出为:

[Test, , Test, , Test]
正如预期的那样,但第二次是:

]

我不知道时间意味着什么。

你能用硬编码的值创建一个简单的例子来重现你的问题吗?你需要什么strText=reader.nextLine.substring9;对于为什么是9?另外,您可能希望在调试日志中显示您正在读取的确切值,因为我敢打赌您没有读取预期的值。您确定数组的某些元素不是换行符,将尾随的]保留在自己的行上吗?甚至回车字符,有时会有效地擦除显示的行?您在哪里输出?文件或帧?strText=reader.nextLine.substring9;因为文件中写着C1Notes:我只想要用户键入的内容。