Java StreamTokenizer quoteChar()方法与示例

StreamTokenizer类quoteChar()方法 (StreamTokenizer Class quoteChar() method)

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

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

  • quoteChar() method denotes that matching pairs of this character delimiter, string constants in this StreamTokenizer. When nextToken() method encounters a string constant, ttype field value is set to the string delimiter and the sval field is set to the content of this string.

    quoteChar()方法表示与此字符定界符(此StreamTokenizer中的字符串常量)的匹配对。 当nextToken()方法遇到字符串常量时,会将ttype字段值设置为字符串定界符,并将sval字段设置为该字符串的内容。

  • When a string quote character is encountered then a string is recognized, made of all characters after, the string quote character up to the next occurrence of that similar string quote char or line exit, EOF. Escape sequences "\n", "\t" is recognized and changed to single characters as the string is parsed.

    当遇到字符串引号字符时,将识别由字符串引号字符组成的字符串,该字符串由其后的所有字符组成,直到下一次出现该相似的字符串引号char或行出口EOF。 解析字符串时,转义序列“ \ n”,“ \ t”被识别并更改为单个字符。

  • quoteChar() 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.

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

  • quoteChar() method does not throw an exception at the time of quote character.

    quoteChar()方法在引号字符时不会引发异常。

Syntax:

句法:

    public void quoteChar(int character);

Parameter(s):

参数:

  • int character – represents the character.

    int字符 –表示字符。

Return value:

返回值:

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

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

Example:

例:

// Java program to demonstrate the example 
// of void quoteChar(int character) method of StreamTokenizer
import java.io.*;
public class QuoteChar {
public static void main(String[] args) {
String str = "Hi, This is \n a mathematical expression :\n " +
" 2 * 4 = 8 " + "8 + 5 = 13";
try {
// Instantiates FileOutputStream  and ObjectOutputStream 
FileOutputStream fos_stm = new FileOutputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt");
ObjectOutputStream obj_out_stm = new ObjectOutputStream(fos_stm);
// By using writeUTF() method is to
// write the given string in the file
obj_out_stm.writeUTF(str);
obj_out_stm.flush();
// Instantiates FileOutputStream  and ObjectOutputStream 
ObjectInputStream obj_in_stm = new ObjectInputStream(new FileInputStream("C:\\Users\\Preeti Jain\\Desktop\\programs\\includehelp.txt"));
// Instantiates StreamTokenizer and Reader
Reader reader = new BufferedReader(new InputStreamReader(obj_in_stm));
StreamTokenizer st = new StreamTokenizer(reader);
// By using quoteChar() method is to
// represent the given char '8' as
// quote char
st.quoteChar('8');
// Here, we are considering initially 
// file is not empty
boolean end_of_file = false;
while (!end_of_file) {
// By using nextToken() method is to
// parse the next token from the stream
int token = st.nextToken();
switch (token) {
case StreamTokenizer.TT_EOF:
System.out.println("End of File Found");
end_of_file = true;
break;
case StreamTokenizer.TT_EOL:
System.out.println("End of Line Found");
break;
case StreamTokenizer.TT_WORD:
System.out.println("word: " + st.sval);
break;
case StreamTokenizer.TT_NUMBER:
System.out.println("number: " + st.nval);
break;
default:
System.out.println((char) token + " Found.");
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

Output

输出量

@ Found.
word: Hi
, Found.
word: This
word: is
word: a
word: mathematical
word: expression
: Found.
number: 2.0
* Found.
number: 4.0
= Found.
8 Found.
+ Found.
number: 5.0
= Found.
number: 13.0
End of File Found

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545207.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

decode 实例

以往相关材料: http://blog.csdn.net/arrowzz/article/details/17144651 http://blog.csdn.net/arrowzz/article/details/17144669表id,name,score1,小明,胜2,小明,胜3,小李,负4,小李,负5,小明,负6,小李,胜7,小李,胜效果name,胜,负小明,2,1小李,2,2创建表&#xf…

5种SpringBoot热部署方式,你用哪种?

来源 | my.oschina.net/ruoli/blog/1590148Spring Boot 中 5 种热部署方式如下:1、模板热部署2、使用调试模式Debug实现热部署3、spring-boot-devtools4、Spring Loaded5、JRebel接下来我们分别来看。1、模板热部署在 Spring Boot 中,模板引擎的页面默认…

IBM 前面板显示信息提示

ps1 指示灯:当此指示灯发亮时,表明电源1 出现故障。 ps2 指示灯:当此指示灯发亮时,表明电源2 出现故障。 temp 指示灯:当此指示灯发亮时,表明系统温度超出阈值级别。 风扇指示灯:当此指…

ContextMenu长按事件

/* ContextMenu菜单就是长按某一个组件,就会在屏幕的中间弹出ContextMenu,这里设置为长按文本框弹出ContextMenu菜单*/public class MyContextMenu extends AppCompatActivity {/** Called when the activity is first created. */final static int CONT…

observable_Java Observable deleteObserver()方法与示例

observable可观察的类deleteObserver()方法 (Observable Class deleteObserver() method) deleteObserver() method is available in java.util package. deleteObserver()方法在java.util包中可用。 deleteObserver() method is used to remove the given observer (obs) from…

偶尔所得代码片(进程和锁相关)

--杀死相关进程&#xff08;必须要用dba账号sys&#xff09; --alter system kill session session_id, serial#;alter system kill session 500,2568;--select lower(CHR(64ROWNUM)) from dual connect by ROWNUM <126--查进程 select * from v$process; --查锁 select * f…

熬夜都要看完的 Spring 干货!

在 Java 后端框架繁荣的今天&#xff0c;Spring 无疑是最最最火热&#xff0c;也是必不可少的开源框架&#xff0c;像腾讯、阿里、字节跳动等一线互联网公司都选择 Spring 作为基础的开发框架。而 Spring 生态圈里最让人兴奋的莫过于 Spring Boot 框架。他简化了使用 Spring 的…

2014值得期待的Erlang两本新书

在2014年的开头就有这样一个令人振奋的好消息,Erlang有一本新书即将出版 《The Erlang Runtime System》,其作者happi在2013年3月份发布了这本书的写作计划:"The plan is to have the book done by the end of 2013 and published early 2014. ",出版方是O’Reilly,依…

页面分栏LayoutInflater

/* 页面分栏*/ public class TabDemo extends TabActivity {/** Called when the activity is first created. */Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);TabHost tabHost getTabHost();LayoutInflater.from(this).inf…

这么简单的三目运算符,竟然这么多坑?

最近在一个业务改造中&#xff0c;使用三目运算符重构了业务代码&#xff0c;没想到测试的时候竟然发生 NPE 的问题。重构代码非常简单&#xff0c;代码如下&#xff1a;// 方法返回参数类型为 Integer // private Integer code; SimpleObj simpleObj new SimpleObj(); // 其…

Java 邮箱判断 正则表达式

import java.util.Scanner;public final class EmailCheck {public static boolean checkEmail(String email){String regex1 "[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9][.][a-zA-Z0-9]";//字母开头&#xff0c;后加字母或数字&#xff0c;后面加点&#xff0c;后面字母或数…

Java DataInputStream skipBytes()方法与示例

DataInputStream类skipBytes()方法 (DataInputStream Class skipBytes() method) skipBytes() method is available in java.io package. skipBytes()方法在java.io包中可用。 skipBytes() method is used to skip the given number of bytes of data from this DataInputStrea…

nagios客户端nrped服务方式启动脚本

1、平时配置nagios客户端nrped启动最常用的就是在/etc/rc.local文件配置&#xff1a;/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d2、但是还有更好的方式&#xff08;这样方便使用脚本启动或者关闭&#xff09;&#xff1a;在/etc/init.d目录下创建nrped脚…

用好MySQL的21个好习惯!

前言每一个好习惯都是一笔财富&#xff0c;本文分SQL后悔药&#xff0c; SQL性能优化&#xff0c;SQL规范优雅三个方向&#xff0c;分享写SQL的21个好习惯&#xff0c;谢谢阅读&#xff0c;加油哈~1. 写完SQL先explain查看执行计划&#xff08;SQL性能优化&#xff09;日常开发…

第四章图像增强

第四章图像增强1_图像增强的概念2_空间域增强2.1_图像增强的点运算2.1.1_灰度变换2.1.2_直方图均衡化2.1.3 直方图规定化1_图像增强的概念 什么是图像增强&#xff1a;图像增强是采用一系列技术去改善图像的视觉效果,或将图像转换成一种更适合于人或机器进行分析和处理的形式。…

Java DataInputStream readShort()方法(带示例)

DataInputStream类readShort()方法 (DataInputStream Class readShort() method) readShort() method is available in java.io package. readShort()方法在java.io包中可用。 readShort() method is used to read 2 bytes (i.e. 16 bit) of data input and returns a short va…

IP 对应 网址

IP 对应 网址 /* 网址和IP对应的小例子 */try {InetAddress address_1 InetAddress.getByName("www.baidu.com");InetAddress address_2 InetAddress.getByName("10.2.8.13");System.out.println(address_1.toString());System.out.println(address_2.t…

springboot发送qq邮件

springboot发送qq邮件1_开启邮箱相关权限并获取邮箱授权码2_实现功能2.1_添加mail的依赖2.1.1_创建工程时添加2.1.2_在工程中添加2.2_配置文件application.properties配置相关信息2.3_实现代码1_开启邮箱相关权限并获取邮箱授权码 进入账户 开启POP3/SMTP服务并生成授权码 …

反转链表-剑指offer-16

题目&#xff1a;定义一个函数&#xff0c;输入一个链表的头节点&#xff0c;反转该链表并输出反转后链表的头节点。分析&#xff1a;逐个头插&#xff0c;实现反转设置3个指针&#xff1a;head 头节点、prev 前一个节点、 cur 下一个节点注意&#xff1a;链表为空&#xff0c;…

getsimplename_Java类类getSimpleName()方法的示例

getsimplename类类getSimpleName()方法 (Class class getSimpleName() method) getSimpleName() method is available in java.lang package. getSimpleName()方法在java.lang包中可用。 getSimpleName() method is used to return the simple name of the underlying class as…