我正在尝试实现一个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);
我为您提供的小型网络抓取应用程序:网页抓取应用程序
应用从网址获取数据