URL to a File.

I'm trying to save a website in a HTML file with Java.
I tried this:
url = new URL("http://www.google.com");
URI uri = url.toURI();
File f = new File(uri);
f.createNewFile();
But it doesn't work. It says: URI scheme is not "file"
Is there a way to convert a website (example: http://www.google.com) to a HTML file.
Or is there a way to convert the HTML code of a website in a variable in Java? I know it's possible to do a new BufferedReader(new FileReader("file.html")), but is it possible directly from a website?

I'm trying to save a website in a HTML file with
Java.
I tried this:
url = new URL("http://www.google.com");
URI uri = url.toURI();
File f = new File(uri);
f.createNewFile();That's not the same thing as what you said you wanted to do.
The URL you created pointed to Google's home page. When you create a File object based on that URL, it's like trying to overwrite their home page. It doesn't copy the results of the URL to the file.
Read the API docs for details.
But it doesn't work. It says: URI scheme is not
"file"Yeah, apparently that method only lets you write to local files. it won't let you, for example, write a file on www.google.com.
Is there a way to convert a website (example:
http://www.google.com) to a HTML file.
Do you want to create a website or a web page? Presumably the latter.
Or is there a way to convert the HTML code of a
website in a variable in Java? I know it's possible
to do a new BufferedReader(new
FileReader("file.html")), but is it possible directly
from a website?Yeah, from the URL, get the content with, if I recall correctly, "getContent". Then write that result to a file.
It's late at night, I have insomnia, let's try it out....
import java.net.*;
import java.io.*;
public class TestGoogle {
  public static void main(String[] argv) {
    try {
      URL u = new URL(argv[0]);
      InputStream content = (InputStream) u.getContent();
      BufferedReader in = new BufferedReader(new InputStreamReader(content));
      String line;
      PrintWriter out = new PrintWriter(new FileWriter("TestGoogle.txt"));
      while((line = in.readLine()) != null) {
     out.println(line);
      out.close();
    } catch (IOException e) {
      e.printStackTrace();
}That works for the Google home page, although when I pass a search it returns 403. This may be a deliberate decision on Google's part to restrict serving content to bots, which would be ironic. Or maybe I just missed something. Anyway it demonstrates how to use a URL to get content and write it to a file.

Similar Messages

  • Since passing to ML, I have a message, in French, which is: La connexion au serveur a échoué. Les URL de type "file" ne sont pas prises en charges.  Can you tell me what this means and how to get rid of it? thank you.

    What does this message mean?
    La connexion au serveur a échoué.  Les URL de type "file" ne sont pas prises en compte.
    thank you.

    Without more information, ie what were you trying to do when you got this message, it is very hard to answer your question. If you were trying to access a webpage it means the server the page is on had a problem. If you were doing something else please post back and someone may have the answer.

  • Database does not contain a URL for the file

    How do I find out what file/update this is:
    The file digest/hash does not exist in the SUSDB, but I have no idea looking at the windowsupdate or softwaredistribution.log what file it is referring to.
    SELECT  [FileDigest]
          ,[DigestAlgorithm]
          ,[AdditionalHash]
      FROM [SUSDB].[dbo].[tbFileHash] fh
      WHERE fh.FileDigest =0x15B82F101E79C1E2181E43CC8A3CC137CBFDC91D
      or fh.AdditionalHash =0x15B82F101E79C1E2181E43CC8A3CC137CBFDC91D
    0 rows found
    Softwaredistribution.log
    2014-10-07 23:07:04.319 UTC    Error    w3wp.5    ClientImplementation.GetExtendedUpdateInfo    System.ArgumentException: The database does not contain a URL for the file 15B82F101E79C1E2181E43CC8A3CC137CBFDC91D.
    Parameter name: fileDigests
       at Microsoft.UpdateServices.Internal.DataAccess.ExecuteSpGetFileLocations(Byte[][] fileDigests)
       at Microsoft.UpdateServices.Internal.DataAccessCache.GetFileLocations(Byte[][] fileDigests, DataAccess da)
       at Microsoft.UpdateServices.Internal.ClientImplementation.GetExtendedUpdateInfo(Cookie cookie, Int32[] revisionIds, XmlUpdateFragmentType[] fragmentTypes, String[] locales)
       at Microsoft.UpdateServices.Internal.ClientImplementation.GetExtendedUpdateInfo(Cookie cookie, Int32[] revisionIds, XmlUpdateFragmentType[] fragmentTypes, String[] locales)
       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
       at System.Web.Services.Protocols.WebServiceHandler.Invoke()
       at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
       at System.Web.Services.Protocols.SyncSessionlessHandler.ProcessRequest(HttpContext context)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
       at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
       at System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb)
       at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
       at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
       at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
       at System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)
       at System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr managedHttpContext, IntPtr nativeRequestContext, IntPtr moduleData, Int32 flags)

    How do I find out what file/update this is:
    Hows about.. rather than chasing a rabbit down the hole doing whatever you think you're doing...
    We start with this: What problem is it that you're actually trying to solve?
    Lawrence Garvin, M.S., MCSA, MCITP:EA, MCDBA
    SolarWinds Head Geek
    Microsoft MVP - Software Packaging, Deployment & Servicing (2005-2014)
    My MVP Profile: http://mvp.microsoft.com/en-us/mvp/Lawrence%20R%20Garvin-32101
    http://www.solarwinds.com/gotmicrosoft
    The views expressed on this post are mine and do not necessarily reflect the views of SolarWinds.

  • I can not download any files using Safari ? when I choose to download application file the URL include the file name and stop responding. Any help??

    I can not download any files using Safari ? when I choose to download application file the URL include the file name and stop responding. Any help??

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. For instructions, launch the System Preferences application, select Help from the menu bar, and enter “Set up a guest account” (without the quotes) in the search box.
    While logged in as Guest, you won’t have access to any of your personal files or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem(s)?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault in Mac OS X 10.7 or later, then you can’t enable the Guest account. The Guest login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode* and log in to the account with the problem. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    *Note: If FileVault is enabled under Mac OS X 10.7 or later, you can’t boot in safe mode.
    Test while in safe mode. Same problem(s)?
    After testing, reboot as usual (i.e., not in safe mode) and verify that you still have the problem. Post the results of steps 1 and 2.

  • The value should be set for Base image URL and Image file directory

    Hi experts
    Now customer has the following issue.
    XML Publisher concurrent request, using RTF layout template with LOGO, does not generate the LOGO for Excel output.
    but in output formats PDF, it is shown normally.
    from the debug log, we can found the following error message
    ======
    [051812_054716051][][ERROR] Could not create an image. Set html-image-dir and html-image-base-uri correctly.
    ======
    so I tell the customer to do the following action plan.
    1. in XML Publisher Administrator resp > Administration expand the HTML Output section.
    2a. enter a value for 'Base image URI'
    2b. enter a value for 'Image file directory'
    Customer set the value as following and retest this issue,but he found the issue is not solved.
    Base image URI: /u01/r12/ebssnd/apps/apps_st/comn/java/classes/oracle/apps/media/XXSLI_SONY_LIFE_LOGO.gif
    Image file directory: /u01/r12/ebssnd/apps/apps_st/comn/java/classes/oracle/apps/media
    I verified 'Base image URI' and 'Image file directory' settings:
    1) Change output type to HTML.
    2) Click the Preview.
    but the image is correctly displayed on HTML, so I think the issue is caused by user's uncorrectly setting of the base image URL and/or image file directory
    but could anyone give me some advice on which value should be set for Base image URL and Image file directory
    Regards
    shuangfei

    First thing to do is to edit the post and use some tags to format the code as it is unreadable and too much!
    Read the FAQ (https://forums.oracle.com/forums/help.jspa) to find out how to do this.
    Next we need to know the jdev version you are using!
    As the code is generated I would first try to generate it again after the db change.
    Timo

  • TA44469 Quicktime on my Mac runs a URL dot mov file.  On My WINXP Quicktime Pro will not.  Anyone know what's wrong.

    Quicktime on my Mac runs a URL dot mov file.  On My WINXP Quicktime Pro will not.  Anyone know what's wrong.

    I just experienced this exact same issue with my early 2011 15" macbook pro. Since like a month after purchasing it I had issues with the screen randomly going dark on me. I sent it in for repair inder waranty they replaced the gpu and logic board but I continued to have the same issues with the screen randomly going black sometimes I would need to reboot it in order to get the screen to go back on but it happened so infrequently and I used the computer for school so disnt find the time to resend it in to apple. Just last night the screen started to display the blue screen with black verticle lines on it. I called apple and explained to them  the issues that had been ongoing since I purchased the laptop but they said because I was now outside of warantee that any repairs at thia point wouldn't be covered. Fml so glad I spent 2200 on this future proof macbook pro what a joke my sister purchased a toshiba laptop for 300 4 years ago and it still running like a champ. I loved my macbook but at the price I paid I expect it to last longer than 2 years before leaving me high and dry. *** apple??

  • Best way to see if a URL to filesystem file exists?

    What's the best way to test if a file (specified by a URL) exists? I know if I had a file object, I could just do: new File( path ).exists() but File takes a URI not a URL as a constructor param. If it's a file, I can just do this, right?:
    try
         InputStream in = url.openStream();
         in.close();
    catch (IOException e)
         //Assume doesn't exist?
    }But if it's a jar file, that won't work since you can only open a stream to an entry. So for jar files, I do this, right?
    try
         URLConnection conn = url.openConnection();
         if ( conn instanceof JarURLConnection ) ( ( JarURLConnection ) conn ).getJarFile();
    catch (IOException e)
         //Assume doesn't exist?
    }Is there a better way?

    Hi,
    Try the below method which convert the given URL to and check if the file exists
    public boolean isFileExistGivenURL (URL url) {
              if (url == null || !url.getProtocol().equals("file")) {
                return false;
            } else {
                String filename = url.getFile().replace('/', File.separatorChar);
                int pos =0;
                while ((pos = filename.indexOf('%', pos)) >= 0) {
                    if (pos + 2 < filename.length()) {
                        String hexStr = filename.substring(pos + 1, pos + 3);
                        char ch = (char) Integer.parseInt(hexStr, 16);
                        filename = filename.substring(0, pos) + ch + filename.substring(pos + 3);
                return new File(filename).exists();
            }Hope this helps
    Regards,
    Alan Mehio
    London,UK

  • Message d'erreur "Les URL de type "File:" ne sont pas prises en charge".

    Je reçois un message d'erreur "Les URL de type "File:" ne sont pas prises en charge". J'ai trouvé un forum qui dit d'aller effacer le fichier /Bibliothèque/Preferences/com.apple.TimeMachine.plist ... qu'en pensez-vous? et où le trouver? merci

    Hi
    Google translate says
    I get a "The URL of type" File error message: "not supported". I found a forum that said to go erase / com.apple.TimeMachine.plist file Library / Preferences / ... What do you think? and where? thank you
    I have seen this in a Web Browser Similar to this file:///Users/ralph/Desktop/Screen%20shots/
    I have seen it in the Finder > Go Menu > Go to Server (when it should be used in the Go to Folder option)
    J'ai vu cela dans un navigateur Web similaire à cette file:///Users/Ralph/Desktop/écran% 20shots/
    Je l'ai vu dans le Finder> Menu Aller> Aller au serveur (quand il doit être utilisé dans l'option Aller au dossier)
    I am not sure where you are seeing the message.
    You have listed the Messages App and the Time Machine App
    Je ne sais pas où vous voyez le message.
    Vous avez énuméré les messages App and the Machine App Time
    10:21 pm      Friday; September 6, 2013
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.4)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • I upgraded to Lion yesterday. Now I keep getting and error message: there was a problem connecting to the server. URLs with type "file:" are not supported. What server?

    I upgraded to Lion yesterday. Now I keep getting and error message: there was a problem connecting to the server. URLs with type "file:" are not supported. What server? How do I get rid of this.

    Take a look at this link, https://discussions.apple.com/message/16156214#16156214

  • Can LabVIEW download files from the Internet? I know the URLs of the files.

    Can LabVIEW download files from the Internet? I know the URLs of the files.

    Hi bmihura,
    I'm not sure what you what to do - download or open URLs - but I've put together the attached VI.
    I hope it is of some use.
    Charlie Rodway
    Test Design Engineer
    Rolls-Royce Controls and Data Services Ltd
    Attachments:
    WebBrowser.vi ‏21 KB

  • Usage: jinstall URL of configuration file

    I am totally over my head and I hope someone can help.
    I'm supposed to go to the usps.com website to print postage paid overnight delivery mailing labels. The usps website directs me to download a javascript before I can print. I downloaded http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab and extracted the files to /mydocuments/mydownloads/javascriptfromusps (a folder I created).
    When double-clicking on the jinstall icon (or when trying to use the 'run' function on the start button for windows xp, I receive the following error message:
    Usage: jinstall <URL of configuration file>
    If anyone is able to offer some insight it would be most appreciated. My supervisor is none too happy with me, & I've already missed the delivery deadline for today.
    Thank you.

    Based on the link below, it is Java plugin that has to be installed and not javascript...
    Try accessing this URL:
    http://java.com/en/download/windows_automatic.jsp
    You should get prompted to download and install Java plugin - accept the prompt and follow installer instructions. Then go back to USPS web site and try printing labels.

  • Error msg:  Usage: jinstall URL of configuration file

    I'm totally out of my depth. I'm simply trying to print postage paid mailing labels at the usps.com website, but have been directed to install a javascript in order to print.
    It says to download from http://java.sun.com/products/plugin/autodl/jinstall-1_4-windows-i586.cab which I have done.
    I put that on my desktop & extracted files to /mydocuments/mydownloads/javascriptfromusps (a directory I created). Now I've got jinstall.exe. When double clicking on that, or by using the 'run' function from the start button on Windows XP, I receive the following error message.
    Usage: jinstall <URL of configuration file>
    If anyone can offer any insight it would be most appreciated. I have an overnight package delivery that must go out (in fact it is now late), & my supervisor is none too happy.
    Thank you.

    I'm not sure what is happening - the URL that you give is usually for automated download and install of the Sun Java virtual machine/plug-in. Manual installs of that item are usually done from here: http://java.com/en/index.jsp (and then click on "Get It Now")
    If you wish, post the address (and what to do) of the USPS webpage so that someone can take a look and maybe explain.

  • Absolute URL of a file

    Hi:
    Does anyone know how to get the absolute URL of a file? in what form does it exist in

    I can't tell you how to GET it, because I don't know what you know about the file. But I can tell you that it should look like these examples:
    file:///user/bin/whatsit.so
    file://C:/gadget/config.txt
    Also you should be aware that the exact format of the file: URL is not well-understood (by me too) so you might have to use three slashes instead of two, or vice versa.
    Of course this is about a file on a local drive. If you're asking how to get the URL of a file accessible via HTTP or FTP, that's another question. Was that part of what you meant to ask? You weren't very clear.

  • Dynamic url to XML file url in jstl

    Hi!
    What i need to do:
    1. I get some parameters when entering a jsp page
    2. I use these parameters to get an xml file from a server
    3. I get a url to a picture from the xml file and load it
    The problem is when i need to create the url to that xml file.
    1. I read the parameters
    String x = request.getParameter("X");
    String y= request.getParameter("Y");
    2. forming the url to xml file
    this doesnt work:
    <c:import url="http://www.website.com/something/something.jsp?xcoord=x&ycoord=y" var="xml">
    <x:parse...
    this works, but it is static...
    <c:import url="http://www.website.com/something/something.jsp?xcoord=5&ycoord=6" var="xml">
    <x:parse...
    It is propable that i read the parameters in a wrong way... what is the right way? Heh, i hope u understood what i tried to tell. :)

    This is maybe because you are using a String and an Integer.
    Try this:
    int x = Integer.parseInt(request.getParameter("X"));
    int y = Integer.parseInt(request.getParameter("Y"));Happy Coding! :-)
    bye ki

  • Http URL starts with file://

    Hi.
    I need to access the file content which is placed in the local system.
    The format of the url is:
    file://<Server Name>/<FolderName>/FileName
    example: file://pwdf1234/sample/abc,jpg
    Is there any specific criteria if the url starts with file:// or
    Should I configure in Visual administrator if the url starts with file://
    Could you please let me know.
    Regards
    Bala

    Hi Raj.
    Thanks for your reply.
    No, Im not using Link To URL
    It (the url which starts with file://) is a hyperlink.
    If you click from webdynpro UI it should navigate to the actual content.
    If it is a http url(for ex: http://www.google.com), it works but if it is a url which starts with file://
    does'nt seems to work.
    Regards
    Bala
    Edited by: Balachandar P on Dec 26, 2007 5:58 AM

Maybe you are looking for