bootstrap FileInput图片上传如何在java中获取图片的名字,大小,以及如何存储在制定文件夹中

bootstrap FileInput图片上传如何在java中获取图片的名字,大小,以及如何存储在制定文件夹中,第1张

后台获取到文件了么FilegetName就是文件名了

这个方法就是保存文件用的了 调用saveFile(filegetInputStrean,filegetName);

private void saveFile(InputStream inputStream, String fileName) {

        OutputStream os = null;        try {

            String path = "D:\\testFile\\";            // 2、保存到临时文件            // 1K的数据缓冲

            byte[] bs = new byte[1024];            // 读取到的数据长度

            int len;            // 输出的文件流保存到本地文件

            File tempFile = new File(path);            if (!tempFileexists()) {

                tempFilemkdirs();

            }

            os = new FileOutputStream(tempFilegetPath() + Fileseparator + fileName);            // 开始读取

            while ((len = inputStreamread(bs)) != -1) {

                oswrite(bs, 0, len);

            }

        } catch (IOException e) {

            eprintStackTrace();

        } catch (Exception e) {

            eprintStackTrace();

        } finally {            // 完毕,关闭所有链接

            try {

                osclose();

                inputStreamclose();

            } catch (IOException e) {

                eprintStackTrace();

            }

        }

    }

//提示:坐标依次打印在命令符窗口

//提示:坐标依次打印在命令符窗口

//提示:坐标依次打印在命令符窗口

//不就是监听鼠标事件吗?

import javaxswing;

import javaawt;

import javaawtevent;

import javaxswingborderBorder;

/

我想建立个界面,可以加载本机中。

加载后可以通过鼠标点击获得上任意点坐标。

提问者: sunny929929 - 试用期 一级

/

public class MyPicture extends JFrame implements MouseListener{

 private JLabel tipLabel;

 /

 main()

 /

 public static void main(String[] args){

  MyPicture frame = new MyPicture();

   framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

   framesetVisible(true);

    }

/

    constructor

    /

    public MyPicture(){

  setSize(800, 600);//根据要求调整大小

  setLocation(100,100);

  setTitle("获得上任意点坐标");

        setResizable(false);

        Container con=getContentPane();

        ImageIcon bgIcon=new ImageIcon("bgpicjpg");//注意的路径

  ImagePanel backpicPanel=new ImagePanel(bgIcon);

  backpicPaneladdMouseListener(this);

  conadd(backpicPanel,BorderLayoutCENTER);

  tipLabel=new JLabel("--------------------提示:坐标依次打印在屏幕上!--------------------");

  conadd(tipLabel,BorderLayoutSOUTH);

 }

/

 

 /

 public void mousePressed(MouseEvent e){

  int x=egetX();

  int y=egetY();

  String message="("+x+","+y+")";

  tipLabelsetText(message);

  Systemoutprintln(message);

 }

 public void mouseReleased(MouseEvent e){

 }

 public void mouseEntered(MouseEvent e){

 }

 public void mouseExited(MouseEvent e){

 }

 public void mouseClicked(MouseEvent e){

 }

}

/

 类ImagePanel,用于添加背景

 /

class ImagePanel extends JPanel{

 private   Image   img;

    public  ImagePanel (ImageIcon   imageIcon){

     img=imageIcongetImage();

    }

    public  void  paintComponent(Graphics   g){

     superpaintComponent(g);

     gdrawImage(img,0,0,this);

    }

}

以上就是关于bootstrap FileInput图片上传如何在java中获取图片的名字,大小,以及如何存储在制定文件夹中全部的内容,包括:bootstrap FileInput图片上传如何在java中获取图片的名字,大小,以及如何存储在制定文件夹中、用java怎么获得一张图片上的一个文字的坐标点 求高手解答、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9329018.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存