怎么通过Java获取本地图片,这里不能用数据库!方法越多越好,最好能给个实例!呵呵

解决方案 »

  1.   

    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();
    }
    }}
      

  2.   

    能具体点么?用file通过路径获取?但是能不能不同过绝对路径获取啊!
      

  3.   

    这是我给你的一个例子,这个例子测试通过,它可以读取以个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
    }