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();
}
}
}
分享到:
相关推荐
const fileUrl = '/path/to/your/file'; window.location.href = fileUrl; // 直接打开URL进行下载 } ``` 2. 当使用POST请求时,前端需要通过Ajax方式发送请求,并且在Ajax配置中指定responseType为'blob',这样...
在 fake network data (stubbed from file) 和 simulate slow networks 的情况下测试你的应用,在非常差的网络连接情况下检测你的应用行为 在你固定装置的环境下,使用非常差的网络数据编写单元测试 OHHTTPStubs ...
import { File } from '@ionic-native/file'; ``` 然后在构造函数中注入这些服务。 3. **配置相机选项**:在多图片选择功能中,你需要设置`CameraOptions`来控制相机的行为。例如,你可以指定质量、允许用户选择...
- Loading XML bean definitions from file [E:\Eclipse_C\workspace\MyStrutsTest\WebRoot\WEB-INF\classes\applicationContext-beans.xml] - JSR-330 'javax.inject.Named' annotation found and supported for ...
<STLLoaderComponent url="path/to/your/stl/file.stl" /> ); } ReactDOM.render(, document.getElementById('root')); ``` 确保替换`path/to/your/stl/file.stl`为实际的STL文件路径。 总结: 通过以上...
Desktop and file based shortcuts to any object or URL Explorer tree that lets you navigate faster through disks An icon based explorer to manage files in free floating windows Support for 4DOS ...
) - Loading properties file from URL [file:/home/admin/creative-task/conf/config.properties] ``` 如果出现异常日志,例如: ``` [2017-01-05 16:39:39 ERROR] [main] (Main:22) - Could not load properties...
"把URL改了就可用"意味着你可以通过Hugging Face的transformers库下载并加载这个模型,只需要更改合适的API地址或者直接下载到本地,然后在代码中指定本地路径即可。 在Python中,使用Hugging Face的transformers库...
NOTE: It's recommended you delete your optionlist.bin file in the __aio folder when updating to this release as the file structure has changed. + Soft reset Improvements. + Fixed corrupt Language ...
var loadingInstance = this.$loading({ text: '上传中' }); var that = this.$refs[imgType].files[0]; var testUrl = this.uploadUrl; lrz(that) .then(function(message) { var formData = message....
System.err.println("Error loading classifier file \"" + classifierName + "\"."); System.exit(1); } // The available FrameGrabber classes include OpenCVFrameGrabber (opencv_videoio), // DC1394...
Reading from a file 105 Reading byte by byte 106 fs.read(fd, buffer, offset, length, position, callback) 106 Fetching an entire file at once 107 fs.readFile(path, [options], callback) 107 Creating a ...
* for use in loading the Catalina internal classes (by accumulating all of the * JAR files found in the "server" directory under "catalina.home"), and * starts the regular execution of the ...
console.error('Error loading XML file'); } }); ``` 这段代码会请求XML文件,并在成功加载后解析XML数据。 **解析XML:** 一旦我们获取了XML文档,可以使用jQuery的DOM遍历方法来提取所需的信息。例如,`$(xml)...
// 假设pdf文件URL为'/path/to/your/pdf/file.pdf' this.loadPdf('/path/to/your/pdf/file.pdf'); }, }; ``` 在这个组件中,我们创建了一个canvas元素用于渲染PDF页面,并添加了上一页和下一页的按钮。`loadPdf...
[[03 08:58:22,467 INFO ] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:317) - Loading XML bean definitions from file [/home/tomcats/...
this.pdfUrl = getURL('path_to_your_pdf_file.pdf') // 替换为实际PDF文件路径 await this.loadDocument() this.renderPage(1) // 渲染第一页 }, methods: { async loadDocument() { try { this.pdfDoc = ...
Here is the direct URL at Amazon UK (nearest to my home, please don't use another): http://www.amazon.co.uk/exec/obidos/gc-email-order1/ref=g_gc_email/202-6198323-6681414 For more generous amount, ...