`
wandejun1012
  • 浏览: 2690063 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

inputstream to string

    博客分类:
  • java
 
阅读更多

 

final static int BUFFER_SIZE = 4096;  
       
     /  

将InputStream转换成某种字符编码的String  
@param in  
@param encoding  
@return  
@throws Exception  
         */  
             public static String InputStreamTOString(InputStream in,String encoding) throws Exception{  
             
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();  
            byte[] data = new byte[BUFFER_SIZE];  
            int count = -1;  
            while((count = in.read(data,0,BUFFER_SIZE)) != -1)  
                outStream.write(data, 0, count);  
             
            data = null;  
            return new String(outStream.toByteArray(),encoding);  
        }  
 

 

refurl:http://blog.csdn.net/cjjky/article/details/6892443

 

 

分享到:
评论

相关推荐

    XmlToJson:Android库,用于将XML转换为JSON以及将JSON转换为XML

    有两种创建XmlToJson对象的方法:从String或从InputStream 。 String xmlString; // some XML String previously created XmlToJson xmlToJson = new XmlToJson . Builder (xmlString) . build(); 或者 ...

    servlet2.4doc

    The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object. addHeader(String, String) - Method in interface javax.servlet....

    Java文件处理工具类--FileUtil

    public static String readFileAsString(InputStream in) throws Exception { String content = new String(readFileBinary(in)); return content; } /** * Read content from local file to binary byte...

    delphi.fast.zlib.v.1.21

    //rename to original into final code InputStream := TFileStream.Create(InputFileName, fmOpenRead); OutputStream := TFileStream.Create(OutputFileName, fmCreate); DecompressionStream := ...

    C#中压缩字符串

    return Convert.ToBase64String(ms.ToArray()); } /// /// 利用ICSharpCode解压 /// /// <param name="param"></param> /// <returns></returns> public static string IC_decompress(string param) {...

    Expect工具Expectit.zip

    // the stream to where you send commands OutputStream outputStream = ...; Expect expect = new ExpectBuilder()  .withInputs(inputStream)  .withOutput(outputStream)  .build(); expect....

    Android开发人员不得不收集的代码

    inputStream2String, string2InputStream : inputStream 与 string 按编码互转 outputStream2String, string2OutputStream: outputStream 与 string 按编码互转 bitmap2Bytes, bytes2Bitmap : bitmap 与 byteArr 互...

    ganymed-ssh2-build210.jar java远程访问linux服务器操作、上传下载文件

    private String processStdout(InputStream in, String charset){ InputStream stdout = new StreamGobbler(in); StringBuffer buffer = new StringBuffer();; try { BufferedReader br = new BufferedReader...

    Android SampleNetworking

    InputStream inStream = requestStream(builder.toString()); Document doc = streamToXml(inStream); List<RssSnipetVo> items = RssParser.parseItems(doc); return items; } Skeptic: Wait wait wait! So ...

    服务器下载文件

    InputStream fis=new BufferedInputStream(new FileInputStream(path)); System.out.println("----当前路径----"+new File(".").getAbsolutePath()); byte[] buffer = new byte[fis.available()]; fis....

    HTTP请求库java-requests.zip

    Response<String> resp = Requests.post(url).data(map).multiPart("ufile", "/path/to/file")  .multiPart(..., ...).text();请求设置://禁止自动重定向 Response<String> resp = Requests.get(url)....

    strust文件上传

    String fileName = Chinese.toChinese(fileActionForm.getFileName()); //获取文件的名称 //String fileSize = String.valueOf(file.getFileSize()); String fileDate = DateFormat.getDateInstance().format...

    android 串口驱动

    /* Missing read/write permission, trying to chmod the file */ Process su; su = Runtime.getRuntime().exec("/system/bin/su"); /*String cmd = "chmod 777 " + device.getAbsolutePath() + "\n...

    ym_java-YOYOPlayer-src

    * Open inputstream to play. */ public void open(InputStream inputStream) throws BasicPlayerException { log.info("open(" + inputStream + ")"); if (inputStream != null) { m_dataSource = ...

    c# 流断点上传

    int upLoadLength = Convert.ToInt32(HttpContext.Current.Request.InputStream.Length); string file = HttpContext.Current.Server.MapPath("/" + fileName); //string path = HttpContext.Current.Server....

    Android实现复制Assets文件到SD卡

    2. 再用AssetManager的open(String fileName, int accessMode) 方法则指定读取的文件以及访问模式就能得到输入流InputStream。 3. 然后就是用已经open file 的inputStream读取文件,读取完成后记得inputStream....

    MCCUtil 工具的使用

    package teacherclub.util; ... String value = (String) mcc.get("test"); System.out.println(value); } public static void main(String[] args) { bulidCache(); output(); } }

    android开发使用例子

    /** * 为程序创建桌面快捷方式 */ private void addShortcut(){ ... //快捷方式的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_... InputStream inputStream = s.getInputStream(); DataInputStream input = new...

    HttpClient以及获取页面内容应用

    5. 调用HttpResponse的getAllHeaders()、getHeaders(String name)等方法可获取服务器的响应头;调用HttpResponse的getEntity()方法可获取HttpEntity对象,该对象包装了服务器的响应内容。程序可通过该对象获取...

    c# 加密和解密相关代码

    本实例实现时主要用到了string 类的ToCharArray 方法和Convert 类的ToChar 方法,下面分别对它们进行 详细介绍。 (1)string类的ToCharArray 方法 string类的ToCharArray 方法用来将字符串中的字符复制到Unicode ...

Global site tag (gtag.js) - Google Analytics