⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urlread.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.net;

import jmathlib.core.tokens.*;
import jmathlib.core.functions.ExternalFunction;
import java.net.*;
import java.io.*;

/**An external function for reading files over the network*/
public class urlread extends ExternalFunction
{
	public OperandToken evaluate(Token[] operands)
	{

		String s        = "";
        String lineFile = "";;
 		    
        if (getNArgIn(operands) != 1)
			throwMathLibException("urlread: number of arguments < 1");
            
		if (!(operands[0] instanceof CharToken))
			throwMathLibException("urlread: argument must be String");
        
        String urlString = ((CharToken)operands[0]).toString();
        
        // open URL
        URL url = null;
        try
        {
            url = new URL( urlString );
        }
        catch (Exception e)
        {
            throwMathLibException("urlread: malformed url");
        }          
        
        // read file over the network
        try 
	    {			
		    BufferedReader inReader = 
                new BufferedReader(new InputStreamReader( url.openStream() ));
 		    
            while ((lineFile = inReader.readLine()) != null)
		    {		    	
		        s += lineFile + "\n";
		    }

		    inReader.close();
	     }
	     catch (Exception e)
	     {
		    throwMathLibException("urlread: error input stream");
	     }		    

	   

		return new CharToken(s);		
	}
}

/*
@GROUP
net
@SYNTAX
urlread( URL)
@DOC
Read a text file from the network. This function supports many
transfer protocols e.g. http, gopher, ftp, file. 
@EXAMPLE
<programlisting>
urlread("http://www.heise.de/newsticker/");
urlread("file:///c:/home/text.txt");
</programlisting>
@NOTES
.
@SEE
csvread, csvwrite
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -