1、企业开发里常用Writer类的成员方法
Writer append(char c) ; 将指定字符添加到此 writer。
Writer append(CharSequence csq) ; 将指定字符序列添加到此 writer。
Writer append(CharSequence csq, int start, int end) ; 将指定字符序列的子序列添加到此 writer.Appendable。
abstract void close() ; 关闭此流,但要先刷新它。
abstract void flush() ; 刷新该流的缓冲。
void write(char[] cbuf) ; 写入字符数组。
abstract void write(char[] cbuf, int off, int len) ; 写入字符数组的某一部分。
void write(int c) ; 写入单个字符。
void write(String str) ; 写入字符串。
void write(String str, int off, int len) ;写入字符串的某一部分。
2、企业开发里常用Writer 类的成员方法
Writer append(char c);
Writer append(char c) ; 将指定字符添加到此 writer。
/**
@大数据躺过的坑【九月哥】所撰写
Writer append(char c) ; 将指定字符添加到此 writer。
*/
public class WriterDemo {
public static void main(String[] args) {
char c = 'A';
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a char
writer.append('c');
// append a new char
writer.append(c);
// flush the writer to see the result
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
cA
3、企业开发里常用Writer 类的成员方法
Writer append(CharSequence csq);
Writer append(CharSequence csq) ; 将指定字符序列添加到此 writer。
/**
@大数据躺过的坑【九月哥】所撰写
Writer append(CharSequence csq) ; 将指定字符序列添加到此 writer。
*/
public class WriterDemo {
public static void main(String[] args) {
CharSequence csq = "Hello World!";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a sequence and change line
writer.append("This is an example\n");
// flush the writer
writer.flush();
// append a new sequence
writer.append(csq);
// flush the writer to see the result
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
This is an example Hello World!
4、企业开发里常用Writer 类的成员方法
Writer append(CharSequence csq , int start, int end);
Writer append(CharSequence csq, int start, int end) ; 将指定字符序列的子序列添加到此 writer.Appendable。
/**
@大数据躺过的坑【九月哥】所撰写
Writer append(CharSequence csq, int start, int end) ;
将指定字符序列的子序列添加到此 writer.Appendable。
*/
public class WriterDemo {
public static void main(String[] args) {
CharSequence csq = "Hello World!";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a subsequence and change line
writer.append("This is an example\n", 11, 19);
// flush the writer
writer.flush();
// append a new subsequence
writer.append(csq, 0, 5);
// flush the writer to see the result
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
example Hello
5、企业开发里常用Writer 类的成员方法
abstract void close();
abstract void close() ; 关闭此流,但要先刷新它。
/**
@大数据躺过的坑【九月哥】所撰写
abstract void close() ; 关闭此流,但要先刷新它。
*/
public class WriterDemo {
public static void main(String[] args) {
String s = "Hello World";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a string
writer.append(s);
// flush the writer
writer.flush();
// append a new string
writer.append("\nThis is an example");
// flush and close the stream
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
Hello World This is an example
6、企业开发里常用Writer 类的成员方法
abstract void flush();
abstract void flush() ; 刷新该流的缓冲。
/**
@大数据躺过的坑【九月哥】所撰写
abstract void flush() ; 刷新该流的缓冲。
*/
public class WriterDemo {
public static void main(String[] args) {
String s = "Hello World";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// append a string
writer.append(s);
// flush the writer
writer.flush();
// append a new string in a new line
writer.append("\nThis is an example");
// flush the stream again
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
Hello World This is an example
7、企业开发里常用Writer 类的成员方法
void write(char[] cbuf);
void write(char[] cbuf) ; 写入字符数组。
/**
@大数据躺过的坑【九月哥】所撰写
void write(char[] cbuf) ; 写入字符数组。
*/
public class WriterDemo {
public static void main(String[] args) {
char[] c1 = {'h', 'e', 'l', 'l', 'o'};
char[] c2 = {'w', 'o', 'r', 'l', 'd'};
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// write a char array
writer.write(c1);
// flush the writer
writer.flush();
// write a new char array
writer.write(c2);
// flush the stream again
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
helloworld
8、企业开发里常用Writer 类的成员方法
abstract void write(char[] cbuf, int off , int len);
abstract void write(char[] cbuf, int off, int len) ; 写入字符数组的某一部分。
/**
@大数据躺过的坑【九月哥】所撰写
abstract void write(char[] cbuf, int off, int len) ; 写入字符数组的某一部分。
*/
public class WriterDemo {
public static void main(String[] args) {
char[] c = {'h', 'e', 'l', 'l', 'o', 'w', 'o', 'r', 'l', 'd'};
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// write a portion of a char array
writer.write(c, 0, 5);
// flush the writer
writer.flush();
// write another portion of a char array
writer.write(c, 5, 5);
// flush the stream again
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
helloworld
9、企业开发里常用Writer 类的成员方法
void write(int c);
void write(int c) ; 写入单个字符。
/**
@大数据躺过的坑【九月哥】所撰写
void write(int c) ; 写入单个字符。
*/
public class WriterDemo {
public static void main(String[] args) {
int c = 70;
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// write an int that will be printed as ASCII
writer.write(c);
// flush the writer
writer.flush();
// write another int that will be printed as ASCII
writer.write(71);
// flush the stream again
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
FG
10、企业开发里常用Writer 类的成员方法
void write(String str);
void write(String str) ; 写入字符串。
/**
@大数据躺过的坑【九月哥】所撰写
void write(String str) ; 写入字符串。
*/
public class WriterDemo {
public static void main(String[] args) {
String str = "Hello world!";
// create a new writer
Writer writer = new PrintWriter(System.out);
try {
// write a string
writer.write(str);
// flush the writer
writer.flush();
// change line and write another string
writer.write("\nThis is an example");
// flush the stream again
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
Let us compile and run the above program, this will produce the following result −
Hello world! This is an example
11、企业开发里常用Writer 类的成员方法
void write(String str ,int off ,int len);
void write(String str, int off, int len) ;写入字符串的某一部分。
/**
@大数据躺过的坑【九月哥】所撰写
void write(String str, int off, int len) ;写入字符串的某一部分。
*/
public class WriterDemo {
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();
}
}
}
Let us compile and run the above program, this will produce the following result −
Hello world
大数据培训:http://www.baizhiedu.com/bigdata2019