[Java] Integer information of characters in a text file acquired by the read () method

Reference books

Java Picture Book 3rd Edition Nine New Doors to Love Java https://www.amazon.co.jp/Java%E3%81%AE%E7%B5%B5%E6%9C%AC-%E7%AC%AC3%E7%89%88-Java%E3%81%8C%E5%A5%BD%E3%81%8D%E3%81%AB%E3%81%AA%E3%82%8B%E6%96%B0%E3%81%97%E3%81%849%E3%81%A4%E3%81%AE%E6%89%89-%E6%A0%AA%E5%BC%8F%E4%BC%9A%E7%A4%BE%E3%82%A2%E3%83%B3%E3%82%AF/dp/4798150371

Sample program to read character information

ReadText.java


import java.io.FileReader;
import java.io.IOException;

public class ReadText {

	public static void main(String[] args) {
		try {
			FileReader in = new FileReader(args[0]);
			int c;
			String s = new String();
			System.out.println("****Display character integer as it is****");
			while((c = in.read()) != -1) {
				System.out.print(c); //Outputs integer information of characters
				System.out.println();
				s = s + (char)c; //Convert integer information to characters
			}
			System.out.print(s); //Output the character string converted to characters and combined
			in.close();
		} catch (IOException ie) { //Exception class representing I / O exceptions
			System.out.println("No file");
		} catch (Exception e) {
			System.out.println("No file specified");
		}
	}
}

aiueo.txt


AIUEO
Kakikukeko
SA Shi Su Se So

A line break is also inserted after the last" so "

Execution result

Execution result


****Display character integer as it is****
12354
12356
12358
12360
12362
10
12363
12365
12367
12369
12371
10
12373
12375
12377
12379
12381
10
AIUEO
Kakikukeko
SA Shi Su Se So

One hiragana is represented by 5 and line breaks are represented by 10.

10 appears 3 times. It seems that the line break is 10 because there is a line break at the end of each line in aiueo.txt.

Input / output is more troublesome than PHP

Maybe not only PHP but also Ruby can be written more easily.

However, since I have to describe the method of exchanging data with the text file one by one, I feel that I can see the contents and deepen my understanding.

Recommended Posts

[Java] Integer information of characters in a text file acquired by the read () method
Get the public URL of a private Flickr file in Java
The story of forgetting to close a file in Java and failing
Sample program that returns the hash value of a file in Java
[Java] Handling of JavaBeans in the method chain
Read a string in a PDF file with Java
Measure the size of a folder in Java
[Java] Read the file in src / main / resources
[Java] Judgment by entering characters in the terminal
Call a method of the parent class by explicitly specifying the name in Ruby
Read the packet capture obtained by tcpdump in Java
[Java] Get the file in the jar regardless of the environment
[Java] How to display the day of the week acquired by LocalDate, DateTimeformatter in Japanese
A quick explanation of the five types of static in Java
Activate Excel file A1 cell of each sheet in Java
Create a method to return the tax rate in Java
Summary of values returned by the Spliterator characteristics method #java
Easily read text files in Java (Java 11 & Java 7)
Examine the system information of AWS Lambda operating environment in Java
Read Java properties file in C #
About the method to convert a character string to an integer / decimal number (cast data) in Java
Check when double-byte characters are garbled when storing the information acquired by API etc. in the MySQL database.
Unzip the zip file in Java
I read the source of Integer
How to make a key pair of ecdsa in a format that can be read by Java
Read the first 4 bytes of the Java class file and output CAFEBABE
How to store the information entered in textarea in a variable in the method
[Java] I tried to make a maze by the digging method ♪
[Java] Returns a Japanese name file in filename of HTTP header
Read items containing commas in a CSV file without splitting (Java)
Let's create a TODO application in Java 5 Switch the display of TODO
Graph the sensor information of Raspberry Pi in Java and check it with a web browser
How to get the length of an audio file in java
Call the super method in Java
Dynamically increase the number of elements in a Java 2D array (multidimensional array)
Memo: [Java] If a file is in the monitored directory, process it.
How to find out the Java version of a compiled class file
How to get the absolute path of a directory running in Java
Get the result of POST in Java
What is the main method in Java?
Read xlsx file in Java with Selenium
The story of writing Java in Emacs
[Java] Check the number of occurrences of characters
<Java> Quiz to batch convert file names separated by a specific character string with a part of the file name
[Java] Is it unnecessary to check "identity" in the implementation of the equals () method?
Let's create a versatile file storage (?) Operation library by abstracting file storage / acquisition in Java
Validate the identity token of a user authenticated with AWS Cognito in Java
I can't remember the text file input / output in Java, so I summarized it.
Cause of is not visible when calling a method of another class in java
Read the file line by line VS read at once
The story of low-level string comparison in Java
JAVA: jar, aar, view the contents of the file
Create a CSR with extended information in Java
About the idea of anonymous classes in Java
A story about the JDK in the Java 11 era
[Java] Dynamic method call by reflection of enum (enum)
The order of Java method modifiers is fixed
The story of learning Java in the first programming
Provisional memo when the name of the method parameter of the Java class cannot be obtained by reflection in the Eclipse plug-in project.
Feel the passage of time even in Java
A bat file that uses Java in windows