【发布时间】:2015-03-20 01:36:07
【问题描述】:
我创建了一个字符串数组String[] arr 来保存我文件中的所有内容:
String[] contentarr=file.openfile();
稍后当我尝试将此字符串数组转换回字符串时:
String contentstr=Arrays.toString(contentarr);
它不断给我错误arr cannot be resolved as a variable。有什么线索吗?
更新代码(学习 Java 第 1 周。尝试在线学习一些教程但不知道如何修复此错误):
package readText;
import java.io.IOException;
import java.util.Arrays;
public class FileData {
public static void main(String[] args) throws Exception {
String file_path1 = "F:\\CampusImages.txt";
String file_path2 = "F:\\CampusImageIDs.txt";
try{
ReadFileLocal file = new ReadFileLocal(file_path1);
String[] aryLines = file.openFile(); //Already wrote openFile function in another file.
int i;
for (i=0; i<aryLines.length; i++){
System.out.println(aryLines[i]);
}
}
catch(IOException e) {
System.out.println(e.getMessage());
}
String all=Arrays.toString(aryLines); //ERROR: aryLines cannot be resolved as a variable.
WriteFile content = new WriteFile( file_path2, true);
content.WriteToFile("Write from here: ");
System.out.println(content); // Also, is the writing part code right?
}
}
【问题讨论】:
-
变量还在作用域内吗?
-
贴出给你错误的代码,而不是你修改过的代码
-
请发布您的整个课程