aspose file tools*
The moose likes Java in General and the fly likes Files from a directory is not being recognized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Files from a directory is not being recognized" Watch "Files from a directory is not being recognized" New topic
Author

Files from a directory is not being recognized

Teja Nakirikanti
Greenhorn

Joined: Oct 18, 2011
Posts: 3

expected output
===========
<file name>.txt
<file name>.txt
<file name>.txt
:
:
:
k,v
k,v
k,v
:
:
:

result we got::
<file name>.txt
<file name>.txt
<file name>.txt
:
:
:
k,v of only first class

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
There is not enough information here to make it easy to answer your question. You don't tell us what the program is doing, you don't tell us what's in the files. I can see multiple file names, and I guess the "k,v" lines are "key, value"? From one of the files? Only some of the files, or all of the files?

For good measure, you could point to specific lines that you expected to behave differently; for example, if there's a loop that is supposed to be reading more than one line of the file, where is it? This both shows that you have thought through the problem and have a specific question, and makes it easier for those of us volunteering our time to help you.

Please use code tags to format the code; it is to your advantage, since people are more likely to just skip trying to help rather than attempting to plow through unformatted code.

rc
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,

By posting only the code and the expected output it's difficult to figure out what is your goal to achieve. I tried to ran the code and removed many unused variables. The final code looks like below.



Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
I don't know if it is this that is causing the problem (because as Ralph and John say, it's difficult to know what the problem is), but line 29 is definitely wrong.
Search the forum for posts about comparing Strings.


Joanne
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36566
    
  16
It’s much easier to read code if you indent correctly; use spaces only, not tabs. Set up your editor to change tab to 4 spaces automatically. And put spaces around binary operators (eg ==) not around unary operators (i++ is better than i ++).
Teja Nakirikanti
Greenhorn

Joined: Oct 18, 2011
Posts: 3

process done::
----------------------
1.Recognize the folder ,then iterating each of the files.
2.Read each line of the file to skip the unnecessary data and read all the k,v pairs.
3.Put them in the TreeMap for the sorting based on values( while inserting i am reversing the places of k,v )
this process is done for all the files in the folder(here comes the problem as i mentioned)
4.Now convert the Tree Map to Linked Hash Map for the order to be maintained while writing in to a file where they are displayed as normal k,v pairs (ie; while writing to the file v,k pairs of Tree Map are converted to k,v pairs)

I wrote the code to display the file name first then the k,v pairs from that file
But the out put is that the first class k,v pairs are only read and the rest is skipped but the file names are being read.



In consideration of the reply::
-----------------------------------------
1.k,v refers to key, values.

2.The file in the directory contains data like the dat given bellow and same structure is found in all the files.
SearchRequest
TransactionInformation.TransactionControlNumber: 1371010101280003
TransactionInformation.Priority: null
FingerData.Position: 1
FingerData.Position: 2
FingerData.Position: 3
FingerData.Position: 4
FingerData.Position: 5
FingerData.Position: 6
FingerData.Position: 7
FingerData.Position: 8
FingerData.Position: 9
FingerData.Position: 10
TargetGalleries: fingerPlain-1,fingerLatent-1,exceptionFingerPlain,
SUCCESS
3272060107390021,3.0312126
3573021702300001,2.728711
3173015811550002,2.4808035
3328023112300007,2.1470318
3175036405300002,2.0835547
7371045209380001,1.4756335
1671046105520001,1.4315698
7502034101500001,1.1825134
3174095204390002,0.9443519
1306014503350001,0.7167574
3173014203420002,0.67425823
3171080502520003,0.46428326
3173010903500003,0.40578112
3175100112570005,0.328002
3171077112400014,0.32794788
3325074504530001,0.20473967

1371054509380001,2.3803377
3272026912410001,1.4075888
3171015707400001,0.82567614
3328131112500006,0.79991835
3171011804580003,0.72508544
7371071209680002,0.7185777
1903034506620003,0.44315025
3171016009600004,0.44152263
1371031512360001,0.4335363
3175071501490007,0.40575165
3175044211580002,0.3450352
3175072902720006,0.30085668
3576021305740003,0.27913237
6472050507640004,0.24619599
3327093110670004,0.18189958
1810041005700002,0.030490799



3.The problem is that the control is coming out of the while loops after reading the first line from the files to be more certain, i found the problem must be between the lines 41 to 54. when the iteration for 2nd file started, the variable is happening to null or the break statement is happening to be executed. since then the control is coming out of the loop.

Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3169
    
  10
Teja Nakirikanti wrote:i found the problem must be between the lines 41 to 54.

As I said in my last post, there is a problem on line 41*. I don't know if it is the only problem but you need to fix that first before trying anything else.


*My previous post referred to line 29. That was in John's version of your code. Now that code tags have been added to your original post, we can see that it is line 41 in that version of the code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Files from a directory is not being recognized
 
Similar Threads
Java I/O for two file
How Do I read Names in A text File In A reverse Order
Problem in file transfer
declaring array of vectors
compare two text files