首页 新闻 赞助 找找看

用SmartUpload实现上传下载怎么把file转换成byte[]

0
悬赏园豆:5 [已解决问题] 解决于 2013-05-03 01:56
用SmartUpload实现上传下载怎么把file转换成byte[]
QXC的主页 QXC | 初学一级 | 园豆:135
提问于:2013-01-06 14:12
< >
分享
最佳答案
1

文件流操作

           using System.IO;
           byte[] buffArr = new byte[1024];
            using (FileStream fs = new FileStream(@"D:\123.txt", FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader sr = new BinaryReader(fs))
                {
                    buffArr = sr.ReadBytes(1024);
                }
            }
收获园豆:5
滴答的雨 | 老鸟四级 |园豆:3681 | 2013-01-06 14:30

LZ 要的是 JAVA代码

geass.. | 园豆:1821 (小虾三级) | 2013-01-06 16:33

应该是了。。。

Java看这里:http://blog.163.com/jameswh_2004/blog/static/44698131201032804741644/

public static byte[] readFile(String filename) throws IOException ...{

    File file =new File(filename);
    if(filename==null || filename.equals(""))
    ...{
      throw new NullPointerException("无效的文件路径");
    }
    long len = file.length();
    byte[] bytes = new byte[(int)len];

    BufferedInputStream bufferedInputStream=new BufferedInputStream(new FileInputStream(file));
    int r = bufferedInputStream.read( bytes );
    if (r != len)
      throw new IOException("读取文件不正确");
    bufferedInputStream.close();

    return bytes;

}

滴答的雨 | 园豆:3681 (老鸟四级) | 2013-01-06 16:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册