K
K
KirillIvanov282015-12-13 19:35:33
Java
KirillIvanov28, 2015-12-13 19:35:33

How to assign a variable of type String the text of a .text file?

Sorry for not being able to figure it out...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Malyarov, 2015-12-13
@KirillIvanov28

Maybe a .txt file?
Class:
FileReader(String path to file) ?

// Демонстрация применения FileReader. 
// Эта программа использует оператор try-с-ресурсами. Требует JDK 7. 
import java.io.*;
class FileReaderDemo { 
     public static void main(String args[]) { 
               try ( FileReader fr = new FileReader("FileReaderDemo.java") ) { 
               int с ;
               // Читает и отображает файл. 
               while((c = fr.read(J) != -1) System.out.print((char) c);
             } 
             catch(IOException e) { System.out.println("I/O Error: " + e)}
       }
}

This is an example from a book. The Complete Guide Herbert Schildt.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question