Una vez tenemos el documento un array de bytes podremos hacer lo que queramos con él.
public static byte[] leerDocumento(URL url) throws IOException { URLConnection connection = url.openConnection(); InputStream in = null; try { in = connection.getInputStream(); } catch (FileNotFoundException e) { return null; } catch (ConnectException e) { e.printStackTrace(); return null; } int contentLength = connection.getContentLength(); ByteArrayOutputStream tmpOut; if (contentLength != -1) { tmpOut = new ByteArrayOutputStream(contentLength); } else { tmpOut = new ByteArrayOutputStream(16384); } byte[] buf = new byte[512]; while (true) { int len = in.read(buf); if (len == -1) { break; } tmpOut.write(buf, 0, len); } in.close(); tmpOut.close(); byte[] array = tmpOut.toByteArray(); return array; }
Busca URLs en un texto y las convierte en un enlace con la URL como texto enlazable y sin title.
function SnTurls(texto) SnTurls = texto Set regx = New RegExp regx.Pattern = "http:\/\/[a-z]+\.[a-z]+\.[a-z]+\/" set matchs = regx.Execute(texto) for each match in matchs SnTurls = Replace(SnTurls, match, "<a href=""" & match & """>" & match & "</a>") next end function
Para que validemos un url en un campo de texto
bool IsValidEmail(string strIn) { // Return true if strIn is in valid e-mail format. return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0- 9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); }
http://username:password@hostname/path/directory/file.php?arg=