I am writing a code to read in a mips file to look for data dependencys, but when i read the file in i get all kinds of goofy stuff coming in as well, thanks in advance for any help.

import java.io.*;
import java.util.*;
public class hw {
		static Scanner inScan = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		System.out.println("Please enter the file name");
		String filename = inScan.next();
	
	ArrayList read= loadFile (filename);
	for (int i=0; i<read.size(); i++)
        System.out.println(i+1 + ":\t" + read.get(i));
	
	
	
	}
	 public static ArrayList loadFile(String fileName) throws Exception{
		 String line;
	ArrayList file= new ArrayList();
	BufferedReader in = new BufferedReader(new FileReader(fileName));
	 while ((line = in.readLine()) != null) 
         file.add(line);
     in.close();
	return file;
	}

}

Here is my Input file:

sub 8, 1, 2
lw 5, 0, 7
sw 1, 12, 4
add 4, 9, 5
addi 6, 6, 1
add 7, 4, 2
beq 9, 5, 40

and the OUTPUT is:

1:	{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf330
2:	{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fmodern\fcharset0 CourierNewPSMT;\f2\fswiss\fcharset0 ArialMT;
3:	}
4:	{\colortbl;\red255\green255\blue255;}
5:	\margl1440\margr1440\vieww9000\viewh8400\viewkind0
6:	\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural\pardirnatural
7:	
8:	\f0\fs24 \cf0 \
9:	
10:	\f1 sub 8, 1, 2
11:	\f0 \
12:	
13:	\f1 lw 5, 0, 7\
14:	sw 1, 12, 4
15:	\f0 \
16:	
17:	\f1 add 4, 9, 5
18:	\f0 \
19:	
20:	\f1 addi 6, 6, 1
21:	\f2 \
22:	
23:	\f1 add 7, 4, 2\
24:	beq 9, 5, 40}

Recommended Answers

All 3 Replies

What did you use to write your file? Because if your file were the simple text you claim it to be, you wouldn't be getting that.

Tell you what, open notepad (or vi on a unix system) and open the file with that, and see of you see the same stuff there, as you do here. I'm willing to bet you do.

Did you use Word and save it as a doc rather than a txt file?

No I used text edit on a mac and saved it as javatest.txt

I'd agree with masijade. It looks like embedded RTF style info to me. Try to save the file as plain text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.