Read url to string in few lines of java code

Now that some time has passed since the original answer was accepted, there’s a better approach: String out = new Scanner(new URL(“http://www.google.com”).openStream(), “UTF-8”).useDelimiter(“\\A”).next(); If you want a slightly fuller implementation, which is not a single line, do this: public static String readStringFromURL(String requestURL) throws IOException { try (Scanner scanner = new Scanner(new URL(requestURL).openStream(), StandardCharsets.UTF_8.toString())) { … Read more

How can I percent-encode URL parameters in Python?

Python 2 From the documentation: urllib.quote(string[, safe]) Replace special characters in string using the %xx escape. Letters, digits, and the characters ‘_.-‘ are never quoted. By default, this function is intended for quoting the path section of the URL.The optional safe parameter specifies additional characters that should not be quoted — its default value is … Read more

Get the values from the “GET” parameters (JavaScript) [duplicate]

JavaScript itself has nothing built in for handling query string parameters. Code running in a (modern) browser can use the URL object (which is part of the APIs provided by browsers to JS): var url_string = “http://www.example.com/t.html?a=1&b=3&c=m2-m3-m4-m5”; //window.location.href var url = new URL(url_string); var c = url.searchParams.get(“c”); console.log(c); For older browsers (including Internet Explorer), you … Read more

How to lazy load images in ListView in Android

Here’s what I created to hold the images that my app is currently displaying. Please note that the “Log” object in use here is my custom wrapper around the final Log class inside Android. package com.wilson.android.library; /* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file … Read more

Java – class.getResource returns null

For those who use Intellij Idea: check for Settings > Build, Execution, Deployment > Compiler > Resource patterns. The setting contains all extensions that should be interpreted as resources. If an extension does not comply to any pattern here, class.getResource will return null for resources using this extension.

JavaScript – Get Portion of URL Path

There is a property of the built-in window.location object that will provide that for the current window. // If URL is http://www.somedomain.com/account/search?filter=a#top window.location.pathname // /account/search // For reference: window.location.host // www.somedomain.com (includes port if there is one) window.location.hostname // www.somedomain.com window.location.hash // #top window.location.href // http://www.somedomain.com/account/search?filter=a#top window.location.port // (empty string) window.location.protocol // http: window.location.search // … Read more

Trying to Validate URL Using JavaScript

Someone mentioned the Jquery Validation plugin, seems overkill if you just want to validate the url, here is the line of regex from the plugin: return this.optional(element) || /^(https?|ftp):\/\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FFEF])|(%[\da-f]{2})|[!\$&’\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value); Here is where they got it from: http://projects.scottsplayground.com/iri/ Pointed out by @nhahtdh This has been updated to: // Copyright (c) 2010-2013 Diego Perini, MIT licensed // … Read more

How to display image from URL on Android

You can directly show image from web without downloading it. Please check the below function . It will show the images from the web into your image view. public static Drawable LoadImageFromWebOperations(String url) { try { InputStream is = (InputStream) new URL(url).getContent(); Drawable d = Drawable.createFromStream(is, “src name”); return d; } catch (Exception e) { … Read more