write() java |
您所在的位置:网站首页 › write用法及搭配 › write() java |
Java Writer write()方法 java.io.Writer.write(String str,int off,int len) 写入字符串的一部分。 1 语法 public void write(String str,int off,int len) 2 参数 str:要写入的字符串。 off:开始写入字符的偏移量。 len:要写入的字符数。 3 返回值 返回true。 4 示例 package com.yiidian; /** * 一点教程网: http://www.yiidian.com */ /** * java.io.Writer.write(String str,int off,int len)方法的例子 */ import java.io.*; public class Demo { public static void main(String[] args) { String str = "Hello world!"; // create a new writer Writer writer = new PrintWriter(System.out); try { // write a string portion writer.write(str, 0, 5); // flush the writer writer.flush(); // write another string portion writer.write(str, 5, 6); // flush the stream again writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } } } 输出结果为: Hello world |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |