我正在尝试实现一个 URL 连接,其中包含我的程序读取的单词列表,但目前找不到解决方案。我目前的代码从 .txt 文件中读取,但我需要它从 URL 中读取列表
我试过了:
URL url = new URL("my url ");
URLConnection con = url.openConnection();
InputStream in = con.getInputStream();
String encoding = con.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
String body = IOUtils.toString(in, encoding);
System.out.println(body);
public static List<String> readFileInList(String myFileName)
{
List<String> lines = Collections.emptyList();
try
{
lines =
Files.readAllLines(Paths.get(fileName), StandardCharsets.UTF_8);
}
catch (IOException e)
{
e.printStackTrace();
}
return lines;
}
public static void main(String[] args) throws FileNotFoundException
List l = readFileInList("my file");
char board[][] = {
{'X','A','G','L','K'},
{'Y','U','P','T','K'},
{'Z','Y','N','X','M'},
{'Q','G','E','E','B'},
{'R','O','A','P','Q'}};
System.out.println("");
Search(board);