Results 1 to 1 of 1
  1. #1
    hyperkossan is offline Member
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Default Problem with in InputStreamReader, pls help

    Hello!

    Im trying to create a program that handles I / 0. Basicly I want to write a string to a .txt file. But I am troubled by the fact that I cant read in ,, correctly from the text file..

    here is my program:

    import java.io.*;
    import java.util.*;

    class IOtxt
    {
    public static void main (String[] args)
    {
    try
    {

    Scanner in = new Scanner (System.in, "Cp850");
    String filelocation = in.nextLine ();

    FileOutputStream fos = new FileOutputStream(filelocation);
    OutputStreamWriter osw = new OutputStreamWriter(fos);
    BufferedWriter fout = new BufferedWriter(osw);

    fout.write (text); // my string of text
    fout.close ();

    FileInputStream fis = new FileInputStream(filelocation);
    InputStreamReader isr = new InputStreamReader(fis); // Ive tried to implement "Cp850", "ASCII" and "UTF8" here without result..
    BufferedReader ReadIn = new BufferedReader(isr);

    StringBuffer buffer = new StringBuffer();
    int ch;
    while ((ch = ReadIn.read()) > -1)
    {
    buffer.append((char)ch);
    }
    ReadIn.close();
    String s2 = buffer.toString();
    System.out.println (s2);

    }

    catch (IOException e)
    {
    System.out.println (e);
    }

    }
    }


    I can write the letters into the textfile without problem when I implement "CP850" to Scanner.. but I cant read in into my console from the created textfile :(
    please help! :)
    Last edited by hyperkossan; 12-10-2008 at 08:53 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •