---
title: "StreamTokenizer in Java"  
description: "The StreamTokenizer class allows you to break an input stream into tokens such as words."  
author: "Anupam Mishra"  
published: 2015-11-16  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/11914/streamtokenizer-in-java  
category: "java"  
tags: ["java", "j2ee"]  
reading_time: 1 minute  

---

# StreamTokenizer in Java

It is provide various [fields](https://answers.mindstick.com/qa/96632/explain-about-relationships-and-look-up-fields-in-ms-access) like double nval (the [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) of a number tokens.), sval (the [string](https://www.mindstick.com/interview/22908/what-are-java-string-class-method) given the [character](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) of a [word](https://answers.mindstick.com/qa/37821/which-word-was-declared-as-2017-s-word-of-the-year-by-oxford-dictionary) [token](https://www.mindstick.com/forum/159447/manage-token-expired-in-mern-auth)), and various [constant](https://www.mindstick.com/forum/34714/difference-between-statics-vs-constant-in-c-sharp) fields. \
[Now](https://yourviews.mindstick.com/view/80750/even-google-maps-are-hacked-now) we taken an example, firstly we write [content](https://www.mindstick.com/articles/12369/cms-extension-for-magento-2-advanced-content-manager-2) in a [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) with the help of FileOutputStream (Let’s take ‘abc.txt’.). Then, read that content to find which one is number and which one is word and also be find total numbers of words in a file.

> ```
> import java.io.*;  public class StreamTokenizerEx{   public static void main(String args[])throws IOException{      FileOutputStream fout=new FileOutputStream("abc.txt");  String s="India is Transforming in coming 20 years in future. Now In 2015, india is rapidly growing country in this world";       byte b[]=s.getBytes();//converting string into byte array       fout.write(b);      fout.close();         FileInputStream fin= new FileInputStream("abc.txt");   InputStreamReader ir= new InputStreamReader(fin);   StreamTokenizer st1 = new StreamTokenizer(ir);   int token=0,count=0;    while (true) {           token=st1.nextToken();  if(token== StreamTokenizer.TT_EOF)     break;  if(token== StreamTokenizer.TT_NUMBER)    System.out.println(st1.nval+" Number");  if(token== StreamTokenizer.TT_WORD)    System.out.println(st1.sval+" WORD");                 count++;}     System.out.println("Numbers of Word in the File is :"+count);}  }
> ```

![StreamTokenizer in Java](https://www.mindstick.com/mindstickarticle/f153daef-0b52-4c32-a95b-ab9ad089e18e/images/516da937-1d19-42c5-be9c-eafff2e6694a.png)

>

\

---

Original Source: https://www.mindstick.com/articles/11914/streamtokenizer-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
