Skip to main content
Code Review

Return to Question

added 4 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

I have this kind of file structure

MALE:FooBar:32
FEMALE:BarFoo:23
MALE:FooBar:32
FEMALE:BarFoo:23

Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>

try{
 BufferedReader in = new BufferedReader(new FileReader("people.ser"));
 String s;
 
 while((s = in.readLine()) != null){
 
 String[] var = s.split(":");
 //var[0]=MALE etc etc
 addGender.add(var[0]);
 }
}catch(Exception e){
 e.printStackTrace();
}
  • Is using a delimiter (like a : in this case) to split string considered a bad practice?
  • What about using the array from the splitted string to store it in some place?
  • Are there any alternatives and better file structure?

I have this kind of file structure

MALE:FooBar:32
FEMALE:BarFoo:23

Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>

try{
 BufferedReader in = new BufferedReader(new FileReader("people.ser"));
 String s;
 
 while((s = in.readLine()) != null){
 
 String[] var = s.split(":");
 //var[0]=MALE etc etc
 addGender.add(var[0]);
 }
}catch(Exception e){
 e.printStackTrace();
}
  • Is using a delimiter (like a : in this case) to split string considered a bad practice?
  • What about using the array from the splitted string to store it in some place?
  • Are there any alternatives and better file structure?

I have this kind of file structure

MALE:FooBar:32
FEMALE:BarFoo:23

Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>

try{
 BufferedReader in = new BufferedReader(new FileReader("people.ser"));
 String s;
 
 while((s = in.readLine()) != null){
 
 String[] var = s.split(":");
 //var[0]=MALE etc etc
 addGender.add(var[0]);
 }
}catch(Exception e){
 e.printStackTrace();
}
  • Is using a delimiter (like a : in this case) to split string considered a bad practice?
  • What about using the array from the splitted string to store it in some place?
  • Are there any alternatives and better file structure?
Tweeted twitter.com/#!/StackCodeReview/status/239558023176142849

I have this kind of file structure

MALE:FooBar:32
FEMALE:BarFoo:23

Where I would want to identify the gender and age of person, ::<Gender>:<Name>:<age>

try{
 BufferedReader in = new BufferedReader(new FileReader("people.ser"));
 String s;
 
 while((s = in.readLine()) != null){
 
 String[] var = s.split(":");
 //var[0]=MALE etc etc
 addGender.add(var[0]);
 }
}catch(Exception e){
 e.printStackTrace();
}

is it considered bad using a delimiter ":" to split the files? using the array from the splitted string to store it in some place? or are there any alternatives and better file structure?

  • Is using a delimiter (like a : in this case) to split string considered a bad practice?
  • What about using the array from the splitted string to store it in some place?
  • Are there any alternatives and better file structure?

I have this kind of file structure

MALE:FooBar:32
FEMALE:BarFoo:23

Where I would want to identify the gender and age of person, ::

try{
 BufferedReader in = new BufferedReader(new FileReader("people.ser"));
 String s;
 
 while((s = in.readLine()) != null){
 
 String[] var = s.split(":");
 //var[0]=MALE etc etc
 addGender.add(var[0]);
 }
}catch(Exception e){
 e.printStackTrace();
}

is it considered bad using a delimiter ":" to split the files? using the array from the splitted string to store it in some place? or are there any alternatives and better file structure?

I have this kind of file structure

MALE:FooBar:32
FEMALE:BarFoo:23

Where I would want to identify the gender and age of person, <Gender>:<Name>:<age>

try{
 BufferedReader in = new BufferedReader(new FileReader("people.ser"));
 String s;
 
 while((s = in.readLine()) != null){
 
 String[] var = s.split(":");
 //var[0]=MALE etc etc
 addGender.add(var[0]);
 }
}catch(Exception e){
 e.printStackTrace();
}
  • Is using a delimiter (like a : in this case) to split string considered a bad practice?
  • What about using the array from the splitted string to store it in some place?
  • Are there any alternatives and better file structure?
Source Link
KyelJmD
  • 193
  • 1
  • 1
  • 4

Reading a line from a text file and splitting its contents

I have this kind of file structure

MALE:FooBar:32
FEMALE:BarFoo:23

Where I would want to identify the gender and age of person, ::

try{
 BufferedReader in = new BufferedReader(new FileReader("people.ser"));
 String s;
 
 while((s = in.readLine()) != null){
 
 String[] var = s.split(":");
 //var[0]=MALE etc etc
 addGender.add(var[0]);
 }
}catch(Exception e){
 e.printStackTrace();
}

is it considered bad using a delimiter ":" to split the files? using the array from the splitted string to store it in some place? or are there any alternatives and better file structure?

lang-java

AltStyle によって変換されたページ (->オリジナル) /