• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading a Text file - HELP REQUIRED ASAP

 
Shanmugam Muthukumarasamy
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have some text file in my local drive (Say C:\Test\inputFile.txt". This has the set of lines in it.

I have to read these lines one by one inside my program and based on that I have to determine some logic. Right now I am doing the following steps to read the file:

String inputFile= "C:\\Test\\InputFile.txt";
//readline
try
{
fr = new FileReader(inputFile);
in = new BufferedReader(fr));
}
catch(FileNotFoundException fne)
{
System.out.println("Cons : FileNotFoundException : " + fne.toString());
}

Question 1:
But When I deploy the same code into the WebSphere, Where do I put this file?
Question 2:
When I try to put these files in a seperate directory under a EAR project, Eg.

test (EAR project)
testWeb
testEJB

are the three folders in my project. I have created the folder "myTextFiles" under the "test" (EAR project) folder and I have mentioned this path ("/myTextFiles") in the server classpath.

After this, I am trying to read from the inputFile.txt, using the same above steps, but it throws the FileNotFoundException, when I say

String dataStreamFormatFile = "/InputFile.txt";
or
String dataStreamFormatFile = "InputFile.txt";

Any Suggestions ...???

Thanks in Advance,
Shan.

[ October 04, 2005: Message edited by: Shanmugam Muthukumarasamy ]

[ October 04, 2005: Message edited by: Shanmugam Muthukumarasamy ]

[ October 04, 2005: Message edited by: Shanmugam Muthukumarasamy ]
[ October 05, 2005: Message edited by: Shanmugam Muthukumarasamy ]
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you put the file in the jar with the classes and use getResourceAsStream() to read it?
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A question for you:

What is the usage of the word URGENT to you? I see it used a lot on forums.
I'm sure your use means something very different than mine.
In my culture it is associated with serious things like bleeding to death and a house on fire. Java programming doesn't fit this pattern.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15713
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, it is VERY URGENT that you read this: EaseUp.

To answer your questions:

Question 1:
But When I deploy the same code into the WebSphere, Where do I put this file?


Anywhere on the server where WebSphere is running on, for example in the directory C:\Test.

Question 2:
When I try to put these files in a seperate directory under a EAR project, Eg...


If you put the file inside the EAR file, you should be able to read it using Class.getResourceAsStream() as Norm suggested.

[ October 05, 2005: Message edited by: Jesper de Jong ]
 
Shanmugam Muthukumarasamy
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to Norm Radder & Jesper de Jong for the quick reply on this. I apologise for the the subject to put that as "URGENT". I have changed the subject to ASAP as per you both suggestion.

Hi Jesper de Jong,

Your suggestion is worked for me, thanks a lot again.

Thanks,
Shan.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!