我在String readFileIntoString(字符串路径)中收到错误,因为有人告诉我该做什么,非法启动表达式。
public static void main(String[] args) {
//public class PreProcess {
// Read a file into a string. Takes file path, returns string
/**
*
* @param path
* @return
*/
public String readFileIntoString(String path) {
char[] line = new char[1024];
StringBuilder dataString;
dataString = new StringBuilder(5000);
try {
try (BufferedReader input = new BufferedReader(new FileReader(path))) {
while (true) {
int readLength = input.read(line);
if (readLength == -1)
break;
dataString.append(line, 0, readLength);
}
}
return dataString.toString();
}
catch (IOException e) {
return " ";
}
}
}
答案 0 :(得分:2)
方法内部方法被视为illegal start of expression
public static void main(String[] args) {
public String readFileIntoString(String path) {
}
}
移动
public String readFileIntoString(String path) {}
到main()
答案 1 :(得分:1)
main()
之外。 try{}
块应始终跟在catch{}
或finally{}