Results 1 to 6 of 6

Thread: Streaming Files

  1. #1
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default Streaming Files

    Hi all... I've been considering trying to a third-party program for a game I play... but I can't figure out how to read from a file. The game writes chat logs, but how would I read from them as they are written to...
    e.g
    Java Code:
    start game
    start third-party program (my program) [tpp]
    tpp reads from chat logs
    game writes to chat logs
    tpp reads only the new data from chat logs (HOW DO I DO THIS!)
    I'm not sure whether its possible, but I think it is, I just dont know how. Could be useful for other things too, but this is where I'm at. Sorry, dont have any code, because I hit this logic block while planning it out.

    Thanks for any help in advance,
    Singing Boyo
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    If you have control of the stream, then you could just use a pipe stream. Otherwise, I guess you could continously read/mark/reset the position on a separate thread.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    read/mark/reset? any chance I could get an example? I dont have any way to get control of the stream as far as I know.

    Hmm... one thing, what if I used a BufferedReader on a FileInputStream, and continuously called readLine() (or whatever it is, been using scanner lately) on it. In my opinion, that would ensure that I got the new lines as the came through.

    Thanks for the help,
    SB
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  4. #4
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    this seems to work, but needs work on performance. Edit the test file manually, save, and see the console gets updated as well.

    Java Code:
    import java.io.*;
    public class Test {
      public static void main(String[] args) throws FileNotFoundException{
        InputStream in = new FileInputStream("foo.bar");
        int c;    
        while(true){
          try{
            c = in.read();
            if(c==-1) continue;
            else System.out.print((char)c);
          }catch(IOException ex){}
        }
      }
    }
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    hmmmm seems that if I del some lines of text, it would only update lines after the current mark...
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Well, the chat logs aren't having deleted content, so deleted lines shouldn't be a problem.

    Thanks for the code, haven't tested it yet, but it looks like it'll work.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. video streaming
    By anniya0n in forum JDBC
    Replies: 3
    Last Post: 05-08-2013, 04:21 PM
  2. Help require to capture streaming data
    By jobseeker in forum Java Servlet
    Replies: 1
    Last Post: 04-02-2009, 10:18 PM
  3. Outputstream not streaming.
    By dantestein in forum Networking
    Replies: 2
    Last Post: 03-14-2009, 08:36 AM
  4. simple mp3 streaming
    By zildjohn01 in forum CLDC and MIDP
    Replies: 0
    Last Post: 11-22-2008, 06:27 AM
  5. streaming mp3
    By arnab321 in forum CLDC and MIDP
    Replies: 1
    Last Post: 10-11-2008, 04:08 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
  •