Results 1 to 2 of 2

Thread: Help my project

  1. #1
    Join Date
    Mar 2012
    Posts
    1
    Rep Power
    0

    Default Help my project

    import java.io.*;

    public class chuyenDuLieu
    {
    public static boolean readln(FileInputStream f) throws IOException
    {
    String line = "";

    while (f != null)
    {
    int ch = f.read();

    if (ch < 0)
    {
    f.close();
    f = null;
    }

    if ((ch == 13) || (ch == -1))
    {
    break;
    }
    else if (ch == 10)
    {
    line = "";
    }
    else
    {
    line = line + (char) ch;
    }
    }

    System.out.println(line);

    ByteArrayOutputStream f1 = new ByteArrayOutputStream();

    String s = line;

    byte buf[] = s.getBytes();

    System.out.println(f.toString());

    byte[] b = f1.toByteArray();

    for (int i = 0; i < b.length; i++)

    {
    System.out.print(line);
    }

    OutputStream f2 = new FileOutputStream("xuat.txt");

    f1.writeTo(f2);

    f2.close();

    f1.close();

    return (f1 != null);
    }

    public static void printFile(String filePath1, String filePath2) throws IOException
    {
    FileInputStream f1 = null;
    FileInputStream f2 = null;

    try
    {
    f1 = new FileInputStream(filePath1);
    f2 = new FileInputStream(filePath2);

    while ((f1 != null) || (f2 != null))
    {
    if (!readln(f1))
    {
    f1 = null;
    }

    if (!readln(f2))
    {
    f2 = null;
    }
    }
    }
    catch (FileNotFoundException e)
    {
    e.printStackTrace();
    System.out.println("Can't find file!");
    }
    catch (IOException e)
    {
    e.printStackTrace();
    System.out.println("Can't read file!");
    }
    finally
    {
    if (f1 != null)
    f1.close();
    if (f2 != null)
    f2.close();
    }
    }
    public static void main(String args[])
    {
    try
    {
    printFile("test1.java", "test3.java");
    }
    catch (IOException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }


    I want to transfer the results into txt file. Help me plz

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Help my project

    When posting code, please use the code tags to preserve formatting.

    Also, you don't actually tell us what the problem is. What's preventing you from transferring the results into a text file? Do you get an Exception of some kind? A strange behavior? Something else?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Creating a project in eclipse from existing project
    By Suraiya in forum New To Java
    Replies: 1
    Last Post: 10-08-2011, 10:14 AM
  2. How to convert from Ant project to maven project?
    By jiapei100 in forum New To Java
    Replies: 0
    Last Post: 06-08-2011, 11:01 AM
  3. Adding a project to an existing project
    By Seijuro in forum NetBeans
    Replies: 4
    Last Post: 08-08-2010, 11:15 AM
  4. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 09:12 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
  •