Results 1 to 4 of 4

Thread: java.io ?????

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Can anyone show be a basic example of input out with Java.
    I can do this in vb in two seconds with vb but with java
    it seems to be a pain in the A%@....

    import java.io.*;

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

    int chararacter;
    byte[] hold;

    FileDescriptor in = new FileDescriptor("C:\iotest");
    FileInputStream fileinputstream = new FileInputStream(in);

    while((character = FileInputStream.read(byte[] hold) != -1){
    System.out.println("Reading Data");
    }

    }
    }

  2. #2
    Guest

    Post

    Check out:
    http://java.sun.com
    http://java.sun.com/docs/books/tutor...page-spotlight
    http://java.sun.com/docs/books/tutor.../io/index.html
    http://java.sun.com/docs/books/tutor...lestreams.html

    The following Copy program uses FileReader and FileWriter to copy the contents of a file named farrago.txt into a file called outagain.txt:

    import java.io.*;

    public class Copy {
    public static void main(String[] args) throws IOException {
    File inputFile = new File("farrago.txt");
    File outputFile = new File("outagain.txt");

    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;

    while ((c = in.read()) != -1)
    out.write(c);

    in.close();
    out.close();
    }
    }

    By the way, the "Custom Networking" section will give you code to grab the html and you can put that in your parser (when complete) and render it and have your own browser that you can trust.

  3. #3

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    yeah i checked that block of code out yesterday, off of
    Sun's site but they dont explain how to add in the
    fullpath name ie....

    File inputFile = new File("farrago.txt");
    FileReader in = new FileReader(inputFile);

    Let's say fargo.txt's path is C:\My Documents\fargo.txt


    File inputFile = new File("C:\My Documents\fargo.txt");
    FileReader in = new FileReader(inputFile);

    Then if this is compiled it generates an illegal escape character error. I noticed the variables pathSeparator,
    pathSeparatorChar,separatorChar but Sun fail's to
    explain how to use them.





  4. #4
    Guest
    You almost had it. It found a "\" which is the signal to "escape" the next character's normal meaning. So you need "\\" where you had "\".

    File inputFile = new File("C:\\My Documents\\fargo.txt");

    The separator character idea would be usefull if you coded for different platforms. Unix would use "/" for directories instead of "\" like Dos/Win.

    You have to watch that though because I think I've seen cases where if you put String s = new String("C:\My Documents\fargo.txt"); and then used File inputFile = new File(s);, it may not need the escape character like
    String s = new String("C:\\My Documents\\fargo.txt");

    It came up once or twice before whether or not you need to use the escape character. But keep that in mind.

Posting Permissions

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



Click Here to Expand Forum to Full Width