[英]How to convert a readfile to a read URL?
我正在尝试实现一个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);
我的小网页抓取应用程序: 网页抓取应用程序
该应用从URL获取数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.