Java CharArrayWriter close()方法与示例

news/2024/5/19 0:49:20 标签: java, python, jdbc, spring, linux

CharArrayWriter类close()方法 (CharArrayWriter Class close() method)

  • close() method is available in java.io package.

    close()方法java.io包中可用。

  • close() method is used to close this stream but it does not free the buffer.

    close()方法用于关闭此流,但不会释放缓冲区。

  • close() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    close()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • close() method does not throw an exception at the time of closing the stream.

    close()方法在关闭流时不会引发异常。

Syntax:

句法:

    public void close();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example 
// of void close() method of CharArrayWriter

import java.io.*;

public class CloseOfCAW {
 public static void main(String[] args) {
  CharSequence cs = "Java World!!!";
  CharArrayWriter caw = null;

  try {
   // Instantiates CharArrayWriter
   caw = new CharArrayWriter();

   // By using close() method isto
   // close the CharArrayWriter 
   caw.close();

   // By using append() method is to
   // append cs to the caw still closing
   // the stream
   caw.append(cs);

   // By using toString() method is 
   // to represent the caw as a string
   System.out.print("caw.toString(): " + caw.toString());
  } catch (Exception ex) {
   System.out.println(ex.toString());
  } finally {

   if (caw != null)
    caw.close();
  }
 }
}

Output

输出量

caw.toString(): Java World!!!


翻译自: https://www.includehelp.com/java/chararraywriter-close-method-with-example.aspx


http://www.niftyadmin.cn/n/1255420.html

相关文章

c/c++-判断一个整数是否是质数

#include <cmath> bool isprime(int a) {if(a < 1) return false;int Sqrt sqrt((double)a);for(int i 2; i < Sqrt; i) {if(a % i 0)return false;}return true; }

关于JS动画和CSS3动画的性能差异

本文章为综合其它资料所得。 根据Google Developer&#xff0c;Chromium项目里&#xff0c;渲染线程分为main thread和compositor thread。 如果CSS动画只是改变transforms和opacity&#xff0c;这时整个CSS动画得以在compositor thread完成&#xff08;而JS动画则会在main thr…

路飞学城Python-Day27(复习)

简单的socket通信 import socket client socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect((127.0.0.1, 8080)) msg input(>>>).strip() client.send(msg.encode(gbk)) res client.recv(1024) print(res) client.close() 客户端import socket sk…

c/c++-辗转相除求最大公约数

int gcd(int a, int b) {return b 0 ? a : gcd(b, a % b); }

SSIS - 8.FTP 任务

FTP全称为 File Transfer Protocol&#xff08;文件传输协议&#xff09;&#xff0c;是通过TCP网络将文件从一个服务器传输到另一个服务器。在SSIS包中&#xff0c;FTP任务是用来实现FTP功能的。 一、创建FTP连接管理器 1&#xff09;打开一个空白的SSIS包&#xff0c;在连接管…

PV UV QPS 并发数

TPS&#xff08;Transactions Per Second&#xff09;&#xff1a;每秒事务数 QPS&#xff08;Query Per Second&#xff09;&#xff1a;每秒请求数&#xff0c;QPS其实是衡量吞吐量的一个常用指标&#xff0c;就是说服务器在一秒的时间内处理了多少个请求。 并发数&#xff1…

SqlServer 索引和视图

索引 1、 什么是索引 索引就是数据表中数据和相应的存储位置的列表&#xff0c;利用索引可以提高在表或视图中的查找数据的速度。 2、 索引分类 数据库中索引主要分为两类&#xff1a;聚集索引和非聚集索引。SQL Server 2005还提供了唯一索引、索引视图、全文索引、xml索引等等…