By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,736 Members | 1,982 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,736 IT Pros & Developers. It's quick & easy.

How to read the file

P: 45
Hi
In my project i want to convert the input file to the .doc format. I convert the text file into the .doc file by using the below code

import java.io.*;

public class test1 {

public static void main(String[] args) throws IOException {
FileInputStream fin;
int i;
BufferedReader is = new BufferedReader(new FileReader("C:/tes.txt"));
try
{
try
{
fin=new FileInputStream("C:/tes.txt");
} catch(FileNotFoundException e) {
System.out.println("Input file not found");
return;
}
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Usage:Copyfile From TO");
return;
}
System.out.println("File Read");
BufferedOutputStream bytesOut = new BufferedOutputStream(new FileOutputStream("C:/myFile1.doc"));

// Copy File

try
{
do
{
i=fin.read();
System.out.println(i);
if(i != -1)
bytesOut.write(i);
}while(i!= -1);
} catch(IOException e) {
System.out.println("File error");
}
System.out.println("File Created");

// Code here to read from is, write to bytesOut

bytesOut.close();
}
}

In the same method i also convert the .xls file but in the output the content will be displayed like this

1  A r i a l 1  A r i a l 1  A r i a l 1  A r i a l ﷓ "$"#,##0_);\("$"#,##0\)﷓ ! "$"#,##0_);[Red]\("$"#,##0\)﷓ " "$"#,##0.00_);\("$"#,##0.00\)﷓ ' " "$"#,##0.00_);[Red]\("$"#,##0.00\)﷓ 7 * 2 _("$"* #,##0_);_("$"* \(#,##0\);_("$"* "-"_);_(@_)﷓ . ) ) _(* #,##0_);_(* \(#,##0\);_(* "-"_);_(@_)﷓ ? , : _("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)﷓ 6 + 1 _(* #,##0.00_);_(* \(#,##0.00\);_(* "-"??_);_(@_)

what can i do to see the original message. The powerpoint files also open in the same condition. Please give the solution to solve the problem.

Thanks in advance,
Geethu
Jan 5 '07 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
Hi
In my project i want to convert the input file to the .doc format. I convert the text file into the .doc file by using the below code

import java.io.*;

public class test1 {

public static void main(String[] args) throws IOException {
FileInputStream fin;
int i;
BufferedReader is = new BufferedReader(new FileReader("C:/tes.txt"));
try
{
try
{
fin=new FileInputStream("C:/tes.txt");
} catch(FileNotFoundException e) {
System.out.println("Input file not found");
return;
}
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Usage:Copyfile From TO");
return;
}
System.out.println("File Read");
BufferedOutputStream bytesOut = new BufferedOutputStream(new FileOutputStream("C:/myFile1.doc"));

// Copy File

try
{
do
{
i=fin.read();
System.out.println(i);
if(i != -1)
bytesOut.write(i);
}while(i!= -1);
} catch(IOException e) {
System.out.println("File error");
}
System.out.println("File Created");

// Code here to read from is, write to bytesOut

bytesOut.close();
}
}

In the same method i also convert the .xls file but in the output the content will be displayed like this

1  A r i a l 1  A r i a l 1  A r i a l 1  A r i a l ? "$"#,##0_);\("$"#,##0\)? ! "$"#,##0_);[Red]\("$"#,##0\)? " "$"#,##0.00_);\("$"#,##0.00\)? ' " "$"#,##0.00_);[Red]\("$"#,##0.00\)? 7 * 2 _("$"* #,##0_);_("$"* \(#,##0\);_("$"* "-"_);_(@_)? . ) ) _(* #,##0_);_(* \(#,##0\);_(* "-"_);_(@_)? ? , : _("$"* #,##0.00_);_("$"* \(#,##0.00\);_("$"* "-"??_);_(@_)? 6 + 1 _(* #,##0.00_);_(* \(#,##0.00\);_(* "-"??_);_(@_)

what can i do to see the original message. The powerpoint files also open in the same condition. Please give the solution to solve the problem.

Thanks in advance,
Geethu
Java does not support .doc or .xls formats that well. To manipulate .doc files you should download and use one of the ready made packages e.g the poi package.

However, you are also using the wrong classes for doing this. Try using FileWriter and see if the files produced are different.
Jan 5 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.