Ruby, Ruby Tutorial

Ruby vs Java – Read and Write Text Files

This post demonstrates how to read and write text files in several scenarios. It makes some short references to equivalent Java concepts and codes.

Ruby, Java, and Others

Here is some information about the environment used for this Ruby post.

  • Windows 10
  • Windows command line
  • Notepad++
  • Ruby for Windows
  • Java 8 – JDK
  • Eclipse Mars

Reading and Writing Files

Reading and writing files in Ruby require the use of the Class IO which is part of Ruby’s Core API. Think of it like the Java IO package.

Read and Write in Bulk

In Ruby

In Java

The equivalent Java codes are as follows.

Read and Write line by line

In Ruby

In Java

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like