English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

-
ReadFromFile.java
-
import java.io.*;
import java.sql.*;

public class ReadFromFile
{
public static void main (String [] args) throws IOException
{
BufferedReader fromFile = new BufferedReader(new FileReader("Guest.txt"));

int a = 2000;
String [] sex = new String [a];

for (int i = 0; i < 2; i ++)
{
sex[i] = fromFile.readLine();

System.out.println ("Customer Sex: " +sex[i]);
}
}
}

-
Guest.txt
-
MR Alex 30
MS Alice 20

-
Output
-
MR Alex 30
MS Alice 20

The above is the java file & txt file. It can read the file, but the output i want is:

-
expected output
-
Sex: Male
Name: Alex
Age: 30

Sex: Female
Name: Alice
Age: 20

If MR, MSTR will have sex = Male. If MRS, MDM, MS will have sex = Female.

Other than that, i also like to put the Male/Female into String sex, put the name into String name, and age into int age.

How i can do all of these?

2007-08-15 17:20:32 · 2 answers · asked by scottcky1985 3 in Computers & Internet Programming & Design

2 answers

OK I know crap about java but why not open the file using the

* ODBC Driver for Text

oConn.Open _
"Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"Dbq=c:\somepath\;" & _
"Extensions=asc,csv,tab,txt"

Then specify the filename in the SQL statement:

oRs.Open "Select * From customer.csv", _
oConn, adOpenStatic, adLockReadOnly, adCmdText

Note: If you are using a Tab delimited file, then make sure you create a schema.ini file, and include the "Format=TabDelimited" option.

Don't know if you can use ODBC in java.

2007-08-15 17:27:53 · answer #1 · answered by youngboy1606 7 · 0 0

Serialize it with a StreamReader

2007-08-15 17:26:40 · answer #2 · answered by mdigitale 7 · 0 0

fedest.com, questions and answers