Results 1 to 4 of 4
Thread: Adding output to txt file
- 04-24-2012, 08:28 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Adding output to txt file
Hello I have this method of code
This loads files in .ns format and then reads the npcid and coords etc. What I want to do is when it reads the .ns file I want it to write the files contents to another text file. I have been trying to do this with little success this is the code that I am trying to add. Not sure if this is the correct/best way to do this.Java Code:public static final void loadNPCSpawns(int regionId) { File file = new File("data/npcs/packedSpawns/" + regionId + ".ns"); if (!file.exists()) return; try { RandomAccessFile in = new RandomAccessFile(file, "r"); FileChannel channel = in.getChannel(); ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0, channel.size()); while (buffer.hasRemaining()) { int npcId = buffer.getShort() & 0xffff; int plane = buffer.get() & 0xff; int x = buffer.getShort() & 0xffff; int y = buffer.getShort() & 0xffff; boolean hashExtraInformation = buffer.get() == 1; int mapAreaNameHash = -1; boolean canBeAttackFromOutOfArea = true; if (hashExtraInformation) { mapAreaNameHash = buffer.getInt(); canBeAttackFromOutOfArea = buffer.get() == 1; } World.spawnNPC(npcId, new WorldTile(x, y, plane), mapAreaNameHash, canBeAttackFromOutOfArea); } channel.close(); in.close(); } catch (Throwable e) { Logger.handle(e); } }
Thanks for any help.Java Code:BufferedWriter out = new BufferedWriter(fstream); out.write(npcId, new WorldTile(x, y, plane), mapAreaNameHash, canBeAttackFromOutOfArea);
- 04-24-2012, 02:40 PM #2
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
Re: Adding output to txt file
Wow, this looks a lot like a Runescape bot script or some kind of bot method to me.
So what you are really trying to do is serialize (i.e. flatten) the WorldTile instance. Since you probably want it readable, you would be well served but implementing a toString() method in WorldTile that creates a string containing all the instance data.
- 04-24-2012, 02:55 PM #3
Member
- Join Date
- Dec 2011
- Posts
- 16
- Rep Power
- 0
Re: Adding output to txt file
Hello thanks for the reply! It is for Runescape but not a bot. Its for my rsps. The source that I downloaded has all the spawns packed into a file and I'm trying to unpack them. Could you maybe give me a small example of implementing tostring() method that I could work off of?
- 04-24-2012, 03:36 PM #4
Senior Member
- Join Date
- Apr 2012
- Location
- New York State of Confusion, USA
- Posts
- 137
- Blog Entries
- 1
- Rep Power
- 0
Re: Adding output to txt file
I can do that. This example shows the general idea, but I'm sure it isn't exactly what you want. The returned string will be a non-delimited sequence of characters, so you won't really be able to use it. You need to devise a protocol for how you want the flattened object represented it so you can create a new instance from that representation when you read it back in.
Java Code:class Example { int i=1; int j=2; char c='a'; String name="fubar"; public String toString() { StringBuffer sb = new StringBuffer(); sb.append(i); sb.append(j); sb.append(c); sb.append(name); return sb.toString(); //ironically, using toString here too } }
Similar Threads
-
Lucene: output elaborated data by adding IR information to it
By aneuryzma in forum LuceneReplies: 0Last Post: 02-22-2011, 10:33 PM -
Adding line numbers to code in output file
By misterwebb in forum New To JavaReplies: 2Last Post: 02-14-2011, 12:37 AM -
how to get the resultset output into an output file
By renu in forum New To JavaReplies: 0Last Post: 09-30-2010, 08:16 PM -
how to change the layout of an input file and write to an output file
By renu in forum New To JavaReplies: 8Last Post: 05-12-2010, 07:19 PM -
Search a word(taken from one file) in another file and give the line as the output
By SwapnaNaidu in forum New To JavaReplies: 7Last Post: 11-19-2008, 02:09 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks