高手请进 怎么通过Java获取本地图片,这里不能用数据库!方法越多越好,最好能给个实例!呵呵 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;public class Test { final String pic_path = "D:/aaaa.jpg"; final String out_path = "C:/123.jpg"; public static void main(String[] args) { new Test().getPic(); } public void getPic() { File file = new File(pic_path); try { byte[] b = new byte[1024]; FileInputStream finput = new FileInputStream(file); FileOutputStream fout = new FileOutputStream(out_path); int k; while ((k = finput.read(b)) != -1) { fout.write(b, 0, k); } } catch (Exception e) { e.printStackTrace(); } }} 能具体点么?用file通过路径获取?但是能不能不同过绝对路径获取啊! 这是我给你的一个例子,这个例子测试通过,它可以读取以个TXT文件并转化为一个二维数组,你把代码改一下就可以用。private double[][] loadTextFile(String filepath) throws IOException { InputStream stream = new FileInputStream(filepath); InputStreamReader reader = new InputStreamReader(stream); BufferedReader breader = new BufferedReader(reader); double[][] result = new double[getFileRows(filepath)][2]; String line = breader.readLine(); String[] mid = new String[] {}; int index = 0; while (line != null) { if (line.startsWith("X")) { line = breader.readLine(); } else { mid = line.split(","); result[index][0] = Double.parseDouble(mid[0]); result[index][1] = Double.parseDouble(mid[1]); index++; line = breader.readLine(); } } return result; } private int getFileRows(String filepath) throws IOException { int count = 0; File file = new File(filepath); BufferedReader reader = new BufferedReader(new InputStreamReader( new FileInputStream(file))); String line = reader.readLine(); while (line != null) { if (!line.startsWith("X")) count++; line = reader.readLine(); } reader.close(); return count; } public enum FileType { text, xls } HttpServletRequestWrapper过滤请求中的参数问题 s2sh 搭建框架出现的问题啊??求助 BufferedWriter的write一次写多行 xsl文件自动生成 hibernate中timestamp类型映射问题 Struts2与uploadify图片上传的问题 关于JMS的Message对象 SSH提交说找不到spring的路径 hibernate 中文问题(高分) 如何用DREAMWEAVER和JSP加TOMCAT开发WEB程序? 用jsp写的简易计算器,同一个页面传参的问题 极简单的一个Web应用,Eclipse下能运行,发布到Tomcat下不能用
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;public class Test {
final String pic_path = "D:/aaaa.jpg";
final String out_path = "C:/123.jpg"; public static void main(String[] args) {
new Test().getPic();
} public void getPic() {
File file = new File(pic_path);
try {
byte[] b = new byte[1024];
FileInputStream finput = new FileInputStream(file);
FileOutputStream fout = new FileOutputStream(out_path); int k;
while ((k = finput.read(b)) != -1) {
fout.write(b, 0, k);
} } catch (Exception e) {
e.printStackTrace();
}
}}
InputStream stream = new FileInputStream(filepath);
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader breader = new BufferedReader(reader);
double[][] result = new double[getFileRows(filepath)][2];
String line = breader.readLine();
String[] mid = new String[] {};
int index = 0;
while (line != null) {
if (line.startsWith("X")) {
line = breader.readLine();
} else {
mid = line.split(",");
result[index][0] = Double.parseDouble(mid[0]);
result[index][1] = Double.parseDouble(mid[1]);
index++;
line = breader.readLine();
} }
return result; } private int getFileRows(String filepath) throws IOException {
int count = 0;
File file = new File(filepath);
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(file)));
String line = reader.readLine();
while (line != null) {
if (!line.startsWith("X"))
count++;
line = reader.readLine();
}
reader.close(); return count;
} public enum FileType {
text, xls
}