试图在Octave中打开网址流?

时间:2014-01-03 19:12:13

标签: java matlab octave

尝试在Octave Java Object中实现Java ...但不确定如何打开url流? THX

爪哇

  URL url = new URL("http://www.google.com");
  (new InputStreamReader(url.openStream()));

Octave中的Java ??

urlString = "http://www.google.com";
url = javaObject('java.net.URL',urlString);
stream = javaObject(url.openStream())  % <-------- ????? trying to do something like this
ireader = javaObject('java.io.InputStreamReader',stream);

尝试时:

stream = javaObject(url.openStream())
error: [java] java.net.ConnectException: Connection refused
error: evaluating argument list element number 1

2 个答案:

答案 0 :(得分:2)

根据Java Interface Functions,您必须使用javaMethod

stream = javaMethod('openStream', url);

答案 1 :(得分:1)

如果您只是想提取内容,可以像urlread()一样简单:

octave:3> a = urlread('google.com');
octave:4> a
a = <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage">...

(输出被截断)

帮助:

octave:6> help urlread
'urlread' is a function from the file /usr/lib/octave/3.6.4/oct/i686-redhat-linux-gnu/urlwrite.oct

 -- Loadable Function: S = urlread (URL)
 -- Loadable Function: [S, SUCCESS] = urlread (URL)
 -- Loadable Function: [S, SUCCESS, MESSAGE] = urlread (URL)
 -- Loadable Function: [...] = urlread (URL, METHOD, PARAM)
     Download a remote file specified by its URL and return its content
     in string S.  For example:

          s = urlread ("ftp://ftp.octave.org/pub/octave/README");

     The variable SUCCESS is 1 if the download was successful,
     otherwise it is 0 in which case MESSAGE contains an error message.
     If no output argument is specified and an error occurs, then the
     error is signaled through Octave's error handling mechanism.

     This function uses libcurl.  Curl supports, among others, the HTTP,
     FTP and FILE protocols.  Username and password may be specified in
     the URL.  For example:

          s = urlread ("http://user:password@example.com/file.txt");

     GET and POST requests can be specified by METHOD and PARAM.  The
     parameter METHOD is either `get' or `post' and PARAM is a cell
     array of parameter and value pairs.  For example:

          s = urlread ("http://www.google.com/search", "get",
                      {"query", "octave"});

     See also: urlwrite



Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at http://www.octave.org and via the help@octave.org

(链接到MATLAB documentation,Octave经常反映)

相关问题