Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
bob_lemley
Contributor II
Contributor II

How to use tJava to read the contents of a file

I am trying to read the contents of a text file using a tJava component.  I have been having issues getting java.io.FileInputStream to work.  Does anyone have sample code on how to read a file?

 

Labels (1)
1 Solution

Accepted Solutions
bob_lemley
Contributor II
Contributor II
Author

I ended up asking an AI for the answer and it gave it to me.  So some sample java code to read a file would look like:

// Specify the path to your file
String filePath = "C:\\path\\to\\your\\file.txt";

try {
    java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.FileReader(filePath));
    String line;
    while ((line = reader.readLine()) != null) {
        // Process each line (e.g., print it)
        System.out.println(line);
    }
    reader.close();
} catch (Exception e) {
    e.printStackTrace();
}

View solution in original post

1 Reply
bob_lemley
Contributor II
Contributor II
Author

I ended up asking an AI for the answer and it gave it to me.  So some sample java code to read a file would look like:

// Specify the path to your file
String filePath = "C:\\path\\to\\your\\file.txt";

try {
    java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.FileReader(filePath));
    String line;
    while ((line = reader.readLine()) != null) {
        // Process each line (e.g., print it)
        System.out.println(line);
    }
    reader.close();
} catch (Exception e) {
    e.printStackTrace();
}