Loading file from URL

 

import java.io.BufferedReader;
import java.io.IOException;   
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;   
import java.net.URLConnection;   
import java.util.Map;
import java.util.Properties; 

/**
 * 从某个URL加载文件,可以上网络上的,也可以是本地的
 * @author zqc
 *
 */
public class LoadPropertyFileFromURL
{
    /**
     * 从URL指定位置加载资源
     * 
     * @param url 资源位置
     */
	public static void loadCommonFile(URL url)
	{
		InputStream in = null;   
        URLConnection urlConnection = null;
        
        try  
        {   
        	urlConnection = url.openConnection();   
        	urlConnection.setUseCaches(false);   
        	in = urlConnection.getInputStream();   
            
        	InputStreamReader is = new InputStreamReader(in);
        	BufferedReader br = new BufferedReader(is);
        	
        	String line = br.readLine();
        	while (null != line)
        	{
        		//line = new String(line.getBytes(),"GBK");
        		System.out.println(line);
        		line = br.readLine();
        	}
        }   
        catch (Exception e)   
        {   
            //处理  
        }   
        finally  
        {   
            if (null != in)   
            {   
                try  
                {   
                	in.close();   
                }
                catch (IOException ignore)   
                {
                	//处理
                }   
                catch (RuntimeException ignore)   
                {
                	//处理
                }   
            }   
        }   
	}
	
	/**
	 * 从指定URL位置加载properties文件
	 * 
	 * @param url 资源位置
	 */
	public static void loadPropertyFile(URL url)   
    {   
        Properties properties = new Properties();   
        InputStream in = null;   
        URLConnection urlConnection = null;
        
        try  
        {   
        	urlConnection = url.openConnection();   
        	urlConnection.setUseCaches(false);   
        	in = urlConnection.getInputStream();   
            properties.load(in);   
               
            for (Map.Entry<Object, Object> entry : properties.entrySet())   
            {   
                String key = (String)entry.getKey();   
                String value = (String)entry.getValue();
                System.out.println("key:" + key);
                System.out.println("value:" + value);
            }   
        }   
        catch (Exception e)   
        {   
            //处理  
        }   
        finally  
        {   
            if (null != in)   
            {   
                try  
                {   
                	in.close();   
                }
                catch (IOException ignore)   
                {
                	//处理
                }   
                catch (RuntimeException ignore)   
                {
                	//处理
                }   
            }   
        }   
    }
	
	public static void main(String[] args)
	{
		try
		{
			//LoadPropertyFileFromURL.loadCommonFile(new URL("file:D:/pig.txt"));
			LoadPropertyFileFromURL.loadCommonFile(new URL("file:D:/pig.properties"));
			LoadPropertyFileFromURL.loadPropertyFile(new URL("file:D:/pig.properties"));
		}
		catch (MalformedURLException e)
		{
			e.printStackTrace();
		}
	}

}

 

 

 

Building prefix dict from the default dictionary ... DEBUG:jieba:Building prefix dict from the default dictionary ... Loading model from cache C:\Users\LY-AI\AppData\Local\Temp\jieba.cache DEBUG:jieba:Loading model from cache C:\Users\LY-AI\AppData\Local\Temp\jieba.cache Loading model cost 0.717 seconds. DEBUG:jieba:Loading model cost 0.717 seconds. Prefix dict has been built successfully. DEBUG:jieba:Prefix dict has been built successfully. C:\Users\LY-AI\Desktop\AI\vits-uma-genshin-honkai\python3.9.13\3.9.13\lib\site-packages\gradio\processing_utils.py:183: UserWarning: Trying to convert audio automatically from float32 to 16-bit int format. warnings.warn(warning.format(data.dtype)) Traceback (most recent call last): File "C:\Users\LY-AI\Desktop\AI\vits-uma-genshin-honkai\python3.9.13\3.9.13\lib\site-packages\gradio\routes.py", line 442, in run_predict output = await app.get_blocks().process_api( File "C:\Users\LY-AI\Desktop\AI\vits-uma-genshin-honkai\python3.9.13\3.9.13\lib\site-packages\gradio\blocks.py", line 1392, in process_api data = self.postprocess_data(fn_index, result["prediction"], state) File "C:\Users\LY-AI\Desktop\AI\vits-uma-genshin-honkai\python3.9.13\3.9.13\lib\site-packages\gradio\blocks.py", line 1326, in postprocess_data prediction_value = block.postprocess(prediction_value) File "C:\Users\LY-AI\Desktop\AI\vits-uma-genshin-honkai\app.py", line 42, in audio_postprocess return gr_processing_utils.encode_url_or_file_to_base64(data["name"]) AttributeError: module 'gradio.processing_utils' has no attribute 'encode_url_or_file_to_base64'
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值