> Describe your file format, or, data format on the file.
> Is it a text file with ASCII characters?
Vera のメッセージ:
> > Describe your file format, or, data format on the file.
> > Is it a text file with ASCII characters?
[quoted text clipped - 6 lines]
>
> etc.
This may do the job:
-------------------------------------
char [][] maps = {{'B', '8'}, {'O', '0'}};
for (int i = 0; i < maps.length; ++i){
line = line.replace(maps[i][0], maps[i][1]);
}
Vera - 06 Sep 2006 19:37 GMT
> This may do the job:
> -------------------------------------
> char [][] maps = {{'B', '8'}, {'O', '0'}};
> for (int i = 0; i < maps.length; ++i){
> line = line.replace(maps[i][0], maps[i][1]);
> }
Nope, didn't work :(
hiwa - 06 Sep 2006 23:31 GMT
Vera のメッセージ:
> > This may do the job:
> > -------------------------------------
[quoted text clipped - 4 lines]
>
> Nope, didn't work :(
Should work.
Vera - 07 Sep 2006 02:00 GMT
Maybe I'm doing something wrong... Here's what I have:
-------------------------------------------------------------------------
public class test
{
/* Main Method */
public static void main(String args[]) throws IOException
{
// Promt the user for file name
BufferedReader console = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the file name: ");
String fileName = console.readLine();
// Create a file object
File file = new File(fileName);
// Declare variables
StringTokenizer tokenizer;
String line, element="";
Vector tokens = new Vector();
int e1=0;
try
{
// Start reading the file
FileReader fr = new FileReader(file);
BufferedReader inFile = new BufferedReader(fr);
// Read the file till EOF
while((line = inFile.readLine())!= null)
{
tokenizer = new StringTokenizer(line);
// Checks how many separate parts of the string
e1 = tokenizer.countTokens();
for(int count=0; count < e1; count++)
{
element = (String)tokenizer.nextToken();
Double elementD = Double.parseDouble(element);
// Check for characters
char [][] maps = {{'B', '8'}, {'O', '0'}};
for (int i = 0; i < maps.length; ++i)
{
line = line.replace(maps[i][0], maps[i][1]);
}
// Print number
System.out.println(element);
// Store number in array
tokens.add(element);
}
}
// Sort the vector elements
Collections.sort(tokens);
// Print sorted vector (comma-separated)
System.out.println(tokens);
// Print sorted vector elements
for(int i=0; i<tokens.size(); i++)
{
System.out.println((String)tokens.elementAt(i));
}
// Close the file
inFile.close();
}
catch(Exception exception)
{
System.out.println(exception);
}
} /* End Main Method */
}
-------------------------------------------------------------------------
And it's giving me a NumberFormatException once it gets to the number
with B instead of 8. That's when it stops.
Vera - 07 Sep 2006 02:34 GMT
Nevermind, my mistake. I forgot to replace "element" with "line" which
is what I should've used in the first place. Anyway, it works, now.
Thank you SOOOOOOO much!!!! :-)