简体   繁体   中英

How to convert a readfile to a read URL?

I'm trying to implement a URL connection that has a list of words my program reads, but currently can't find a solution. My code at the moment reads from a .txt file but I need it to read a list from a URL

I've tried:

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);

My small web scraping app for you: web scraping app

The app get data from URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM