LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-11-2006, 11:15 AM   #1
byteframe
Member
 
Registered: Oct 2005
Distribution: Slackware
Posts: 62

Rep: Reputation: 15
Getting character inputs from FileReader in Java.


In java I'm thinking that using FileReader to open a file and read the contents in the right way to go, but for some reason my FileReader object's read() method only returns and int corresponding to what that character is. I need the information from a text file for the declarations of other variables. How would I go about doing this? I fiqured I'd try System.out.println()-ing the information, but again it only spits out the interger value of the characters....ANy suggestions? THank yuo very much.
 
Old 04-11-2006, 12:59 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Here's a quick'n'dirty example that might help:
Code:
import java.io.*;

public class psm060411a
{

  public static void main (String[] args)
  {
    // Check arguments
    if (args.length != 1) {
      System.out.println ("USAGE: test <filename>!");
      return;
    }

    // Open file
    BufferedReader in;		
    try {
      in = new BufferedReader (new FileReader (args[0]));
      String s;
      while ((s = in.readLine ()) != null) {
        System.out.println (s);
      }
      in.close();		
    }
    // Error handler
    catch (IOException e) {
      System.err.println ("Read file error: " + e.getMessage ());
    }
    System.out.println ("Hasta la bye bye!");
  }	
}
Here's corresponding sample output:
Quote:
C:>javac -Xlint:all psm060411a.java

C:>java psm060411a
USAGE: test <filename>!

C:>java psm060411a psm060411a.java
import java.io.*;

public class psm060411a
{

public static void main (String[] args)
{
// Check arguments
...
}
System.out.println ("Hasta la bye bye!");
}
}
Hasta la bye bye!

C:>
'Hope that helps .. PSM
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using mencoder with composite inputs Caysho Linux - Software 1 01-24-2006 03:01 AM
MythTV claims all my inputs are in use. None actually are Pcghost Linux - Software 2 03-24-2005 10:42 AM
No Sound from Motherboard Inputs? braincandy99 Slackware 3 07-18-2004 06:22 AM
Java: Change first character in word to upper AMMullan Programming 4 04-05-2004 03:16 PM
getting info on video inputs Jo_Nak Programming 1 06-16-2003 03:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration