Results 1 to 2 of 2
Thread: Help my project
- 03-30-2012, 11:22 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 1
- Rep Power
- 0
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
- 03-30-2012, 02:57 PM #2
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
-
Creating a project in eclipse from existing project
By Suraiya in forum New To JavaReplies: 1Last Post: 10-08-2011, 09:14 AM -
How to convert from Ant project to maven project?
By jiapei100 in forum New To JavaReplies: 0Last Post: 06-08-2011, 10:01 AM -
Adding a project to an existing project
By Seijuro in forum NetBeansReplies: 4Last Post: 08-08-2010, 10:15 AM -
open existing project project ..
By itaipee in forum EclipseReplies: 1Last Post: 12-28-2008, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks