Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Reading help
#1
This is not related to MapleStory, but it's the technical help section anyways xD If this is inappropriate and it needs to be moved to Rubik's Cube, then do so.


So my current problem is that I want to modify a 2 Mb+ .txt file log to a specific format of my liking. Trying to do this manually is going to take forever, not to mention my computer is pretty slow at updating Notepad in the beginning (but not the end).

One way I've plotted to solving this problem is using programming; in my case, it's Java's FileInputStream (the log has non-alphanumeric characters, which regex utterly fails at working with). But there seems to be a big problem for which I can't find the answer to. Whenever I call the read() method, I always get a null byte (value = 0). Actually in fact FileInputStream seems to think that all of the bytes in the file are null. This is not true. The available() method works fine, and everything else works fine as far as I can tell. read() works fine with any other kinds of data files.

FileReader class also gives me the same BS that FileInputStream does.

 code

What's going on here? And can I get the code to work correctly?
Reply
#2
1. I dunno what formatting you're trying to do, but a proper text editor with regex search+replace might do the trick if it's relatively simple. I don't know what you're talking about with regexes not working with non-alphanumeric characters.

2. in.available() is not necessarily the file size. It's "the number of bytes that can be read from this file input stream without blocking." That is, the number of bytes that can be read without going to the disk, or the number of bytes in the buffer. If you want the file size, use f.length().

3. It works fine for me (I replaced in.available() ith f.length()).
Reply
#3
Spaz Wrote:1. I dunno what formatting you're trying to do, but a proper text editor with regex search+replace might do the trick if it's relatively simple. I don't know what you're talking about with regexes not working with non-alphanumeric characters.

I dunno if regex is suppose to behave in what apparently seems the wrong way or not with non-alphanumerics. For all I know it could just be Vista being really gh3y or something. Or I implemented it wrong (but when I tested my coding on regular text it worked fine).

Spaz Wrote:2. in.available() is not necessarily the file size. It's "the number of bytes that can be read from this file input stream without blocking." That is, the number of bytes that can be read without going to the disk, or the number of bytes in the buffer. If you want the file size, use f.length().

You are right about the convention.

In this case in.available() actually is the file size (not the space on the disk), and I've checked myself in the properties window. Also, I'm sorta exercising caution since I don't know what would happen if read() tried to read something that can't be read. More info on this subject would be nice, though I doubt it's actually going to help solve my problem.

Spaz Wrote:3. It works fine for me (I replaced in.available() ith f.length()).

Doesn't work fine for me. The only thing that you changed was the size of the byte array b.


EDIT: Okay, this is very alarming. ANY file I'm trying this on is giving me an array of bytes full of null values. That wasn't the case before o.O

EDIT2: Nvm, found my problem. *is banging head on desk* read() isn't there -_-; That's rather embarrassing, having this issue for a few days.

Close thread please.
Reply
#4
Hmmm, could you post some sample data, eg the odd 15 - 30 lines?

While using java to do things isnt the wrong way, it may not necessarily be the best way. There're many native commands in Linux/Cygwin, eg sed, tr, awk etc which does things really well. Since you mentioned it's a log file, the format should be consistent, so these commands will likely to get the job done faster than any programming languages can.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)