JAVA WCF 图片上传

java: 

public static void main(String[] args) throws Exception

    {
        try
        {
            StringBuffer sb = new StringBuffer();
            FileInputStream fis = new FileInputStream("D:\\222.jpg");
            BufferedInputStream bis = new BufferedInputStream(fis);
            java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
            byte[] buff = new byte[1024];
            int len = 0;
            while ((len = fis.read(buff)) != -1)
            {
                bos.write(buff, 0, len);
            }
            // 得到图片的字节数组
            byte[] result = bos.toByteArray();



            System.out.println("++++" + byte2HexStr(result));
            // 字节数组转成十六进制
           String str = bytesToHexString(result);



            System.out.println(str);

            //transition tr=new transition();
           // System.out.println(tr.PostSend(str)) ;

            /*
             * 将十六进制串保存到txt文件中
             */
//            PrintWriter pw = new PrintWriter(
//                    new FileWriter("F:\\aaa.txt"));
//            pw.println(str);
//            pw.close();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }





    /*
     * 实现字节数组向十六进制的转换的方法二
     */
    public static String bytesToHexString(byte[] src)
    {
        StringBuilder stringBuilder = new StringBuilder("");
        if (src == null || src.length <= 0)
        {
            return null;
        }
        for (int i = 0; i < src.length; i++)
        {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2)
            {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv);
        }
        return stringBuilder.toString();

    }

WCF:

//str+="0a0140280500a0140280500a014";
            //string filePath = System.Configuration.ConfigurationManager.AppSettings["ServerUpPath"];
            //if ((str.Length % 2) != 0)
            //    str += " ";
            //byte[] returnBytes = new byte[str.Length / 2];
            //for (int i = 0; i < returnBytes.Length; i++)
            //{
            //    returnBytes[i] = Convert.ToByte(str.Substring(i * 2, 2), 16);
            //}
            //if (!Directory.Exists(filePath))
            //{
            //    Directory.CreateDirectory(filePath);
            //}
            //string ImageName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
            //string ImagePath = filePath + ImageName;
            //File.WriteAllBytes(ImagePath, returnBytes);


猜你喜欢

转载自blog.csdn.net/yangangwuwuyangang/article/details/72625613
WCF