Read in a file, check that it meets certain criteria Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Check that a data file contains the expected number of rows and columns of integersRewriting nested for loops to give better formatted outputJava - How to represent the result of an operationPutting read data into a combined file based on certain attributesCheck whether address criteria contain only certain fields or moreRetrying to read a fileJava 8 file read methodFunction that check's file type based on certain keywordsImplementation of stackImproving this TileMapFollow-up 2: Copy File, remove spaces in specific lines
Echoing a tail command produces unexpected output?
How to find all the available tools in macOS terminal?
What does the word "veer" mean here?
Should I use a zero-interest credit card for a large one-time purchase?
Identify plant with long narrow paired leaves and reddish stems
Coloring maths inside a tcolorbox
Selecting the same column from Different rows Based on Different Criteria
What's the purpose of writing one's academic biography in the third person?
How to deal with a team lead who never gives me credit?
2001: A Space Odyssey's use of the song "Daisy Bell" (Bicycle Built for Two); life imitates art or vice-versa?
What does an IRS interview request entail when called in to verify expenses for a sole proprietor small business?
Overriding an object in memory with placement new
How do I stop a creek from eroding my steep embankment?
What would be the ideal power source for a cybernetic eye?
illegal generic type for instanceof when using local classes
How widely used is the term Treppenwitz? Is it something that most Germans know?
Fundamental Solution of the Pell Equation
Seeking colloquialism for “just because”
Why did the IBM 650 use bi-quinary?
Is the Standard Deduction better than Itemized when both are the same amount?
Can an alien society believe that their star system is the universe?
What does this icon in iOS Stardew Valley mean?
Generate an RGB colour grid
Bete Noir -- no dairy
Read in a file, check that it meets certain criteria
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Check that a data file contains the expected number of rows and columns of integersRewriting nested for loops to give better formatted outputJava - How to represent the result of an operationPutting read data into a combined file based on certain attributesCheck whether address criteria contain only certain fields or moreRetrying to read a fileJava 8 file read methodFunction that check's file type based on certain keywordsImplementation of stackImproving this TileMapFollow-up 2: Copy File, remove spaces in specific lines
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
This was my original posting: Check that a data file contains the expected number of rows and columns of integers
I updated the code. Still what could I improve on?
Another question I have is how come my last method fileContent() does not need any throws declaration in the method header?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class FormatChecker2
public static void main(String[] args)
FormatChecker2 tester = new FormatChecker2(); // To avoid every method being static.
if (args.length == 0)
System.out.println("Usage: $ java FormatChecker file1 [file2 ... fileN]");
else
for (String fileName : args)
try
tester.readInTextFile(fileName);
System.out.println(fileName + "");
System.out.println("VALID");
System.out.println();
catch (FileNotFoundException notFound)
System.out.println(notFound.getMessage() + "");
System.out.println(notFound + " (The system cannot find the file specified)");
System.out.println("INVALID");
System.out.println();
catch (NumberFormatException notInt)
System.out.println(fileName);
// String printMessage = notInt.toString().replaceAll("#.*?;", ""); "#" + file +
// ";"
System.out.println(notInt);
System.out.println("INVALID");
System.out.println();
catch (InputMismatchException badContent)
System.out.println(fileName);
System.out.println(badContent);
System.out.println("INVALID");
System.out.println();
catch (IllegalCharacterException delChar)
System.out.println(fileName);
System.out.println(delChar);
System.out.println("INVALID");
System.out.println();
public void readInTextFile(String fileName)
throws FileNotFoundException, IllegalCharacterException, NumberFormatException
File file = new File(fileName);
if (file.exists() && file.isFile())
parseFile(file);
else
throw new FileNotFoundException(fileName);
public void parseFile(File file) throws FileNotFoundException, IllegalCharacterException
Scanner fileScan = new Scanner(file);
String declaredRowCol = fileScan.nextLine().trim();
String[] dimensions = declaredRowCol.split("\s+");
String declaredRowStr = dimensions[0];
String declaredColStr = dimensions[1];
int rowCount = 0;
int colCount = 0;
String notAllNumbers = "";
while (fileScan.hasNextLine())
String line = fileScan.nextLine().trim();
if (!line.isEmpty())
rowCount++;// Counts actual number of rows
Scanner lineScan = new Scanner(line);
while (lineScan.hasNext())
String token = lineScan.next().trim(); // should I include trim?
char letterCheck = token.charAt(0);
// Checks to make sure the content of this file includes only numbers
if (Character.isLetter(letterCheck))
notAllNumbers = letterCheck + "";
colCount++; // Counts actual number of columns, divide by rowCount to get actual
lineScan.close();
// Checks to make sure there is not an extra integer on the first line
if (dimensions.length > 2)
throw new IllegalCharacterException(
"Row and Column have already been provided on the first line of the file. The extra integer: "
+ """ + dimensions[2] + """ + " should not be included.");
else if (!notAllNumbers.isEmpty())
throw new IllegalCharacterException(
"This value in your file: " + """ + notAllNumbers + """ + " is not a number.");
else
formatDimensions(dimensions, declaredRowStr, declaredColStr, rowCount, colCount);
public void formatDimensions(String[] dimensions, String declaredRowStr, String declaredColStr, int rowCount,
int colCount) throws IllegalCharacterException, NumberFormatException, FileNotFoundException
int declaredRow = 0;
int declaredCol = 0;
// Catches if the variables on the first line are of type integer
try
declaredRow = Integer.parseInt(declaredRowStr);
declaredCol = Integer.parseInt(declaredColStr);
fileContent(declaredRow, declaredCol, rowCount, colCount);
catch (NumberFormatException e)
throw new NumberFormatException("This value on the first line of your file:"
+ e.getMessage().substring(17, e.getMessage().length()) + " is not of type integer.");
public void fileContent(int declaredRow, int declaredCol, int rowCount, int colCount)
throws FileNotFoundException, IllegalCharacterException
// Checks to see if row and column matches the actual number of rows and columns
double roundToRealRowCount = (rowCount / 1.0); // This is to account for rounding of
// integer
double roundToRealColCount = (colCount / roundToRealRowCount);// if row or column is not
// divided evenly
if (rowCount != declaredRow)
throw new InputMismatchException("Number of rows declaration: " + "'" + declaredRow + "'"
+ " on first line does not match the actual number of rows in file.");
else if (roundToRealColCount != declaredCol)
throw new InputMismatchException("Number of columns declaration: " + "'" + declaredCol + "'"
+ " on first line does not match the actual number of columns in file.");
java
$endgroup$
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
$begingroup$
This was my original posting: Check that a data file contains the expected number of rows and columns of integers
I updated the code. Still what could I improve on?
Another question I have is how come my last method fileContent() does not need any throws declaration in the method header?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class FormatChecker2
public static void main(String[] args)
FormatChecker2 tester = new FormatChecker2(); // To avoid every method being static.
if (args.length == 0)
System.out.println("Usage: $ java FormatChecker file1 [file2 ... fileN]");
else
for (String fileName : args)
try
tester.readInTextFile(fileName);
System.out.println(fileName + "");
System.out.println("VALID");
System.out.println();
catch (FileNotFoundException notFound)
System.out.println(notFound.getMessage() + "");
System.out.println(notFound + " (The system cannot find the file specified)");
System.out.println("INVALID");
System.out.println();
catch (NumberFormatException notInt)
System.out.println(fileName);
// String printMessage = notInt.toString().replaceAll("#.*?;", ""); "#" + file +
// ";"
System.out.println(notInt);
System.out.println("INVALID");
System.out.println();
catch (InputMismatchException badContent)
System.out.println(fileName);
System.out.println(badContent);
System.out.println("INVALID");
System.out.println();
catch (IllegalCharacterException delChar)
System.out.println(fileName);
System.out.println(delChar);
System.out.println("INVALID");
System.out.println();
public void readInTextFile(String fileName)
throws FileNotFoundException, IllegalCharacterException, NumberFormatException
File file = new File(fileName);
if (file.exists() && file.isFile())
parseFile(file);
else
throw new FileNotFoundException(fileName);
public void parseFile(File file) throws FileNotFoundException, IllegalCharacterException
Scanner fileScan = new Scanner(file);
String declaredRowCol = fileScan.nextLine().trim();
String[] dimensions = declaredRowCol.split("\s+");
String declaredRowStr = dimensions[0];
String declaredColStr = dimensions[1];
int rowCount = 0;
int colCount = 0;
String notAllNumbers = "";
while (fileScan.hasNextLine())
String line = fileScan.nextLine().trim();
if (!line.isEmpty())
rowCount++;// Counts actual number of rows
Scanner lineScan = new Scanner(line);
while (lineScan.hasNext())
String token = lineScan.next().trim(); // should I include trim?
char letterCheck = token.charAt(0);
// Checks to make sure the content of this file includes only numbers
if (Character.isLetter(letterCheck))
notAllNumbers = letterCheck + "";
colCount++; // Counts actual number of columns, divide by rowCount to get actual
lineScan.close();
// Checks to make sure there is not an extra integer on the first line
if (dimensions.length > 2)
throw new IllegalCharacterException(
"Row and Column have already been provided on the first line of the file. The extra integer: "
+ """ + dimensions[2] + """ + " should not be included.");
else if (!notAllNumbers.isEmpty())
throw new IllegalCharacterException(
"This value in your file: " + """ + notAllNumbers + """ + " is not a number.");
else
formatDimensions(dimensions, declaredRowStr, declaredColStr, rowCount, colCount);
public void formatDimensions(String[] dimensions, String declaredRowStr, String declaredColStr, int rowCount,
int colCount) throws IllegalCharacterException, NumberFormatException, FileNotFoundException
int declaredRow = 0;
int declaredCol = 0;
// Catches if the variables on the first line are of type integer
try
declaredRow = Integer.parseInt(declaredRowStr);
declaredCol = Integer.parseInt(declaredColStr);
fileContent(declaredRow, declaredCol, rowCount, colCount);
catch (NumberFormatException e)
throw new NumberFormatException("This value on the first line of your file:"
+ e.getMessage().substring(17, e.getMessage().length()) + " is not of type integer.");
public void fileContent(int declaredRow, int declaredCol, int rowCount, int colCount)
throws FileNotFoundException, IllegalCharacterException
// Checks to see if row and column matches the actual number of rows and columns
double roundToRealRowCount = (rowCount / 1.0); // This is to account for rounding of
// integer
double roundToRealColCount = (colCount / roundToRealRowCount);// if row or column is not
// divided evenly
if (rowCount != declaredRow)
throw new InputMismatchException("Number of rows declaration: " + "'" + declaredRow + "'"
+ " on first line does not match the actual number of rows in file.");
else if (roundToRealColCount != declaredCol)
throw new InputMismatchException("Number of columns declaration: " + "'" + declaredCol + "'"
+ " on first line does not match the actual number of columns in file.");
java
$endgroup$
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
$begingroup$
...but I see fileContent method does havethrows
clause ....
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:32
$begingroup$
all the printing inside the catch clauses look very similar. should be put in a method.
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:34
add a comment |
$begingroup$
This was my original posting: Check that a data file contains the expected number of rows and columns of integers
I updated the code. Still what could I improve on?
Another question I have is how come my last method fileContent() does not need any throws declaration in the method header?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class FormatChecker2
public static void main(String[] args)
FormatChecker2 tester = new FormatChecker2(); // To avoid every method being static.
if (args.length == 0)
System.out.println("Usage: $ java FormatChecker file1 [file2 ... fileN]");
else
for (String fileName : args)
try
tester.readInTextFile(fileName);
System.out.println(fileName + "");
System.out.println("VALID");
System.out.println();
catch (FileNotFoundException notFound)
System.out.println(notFound.getMessage() + "");
System.out.println(notFound + " (The system cannot find the file specified)");
System.out.println("INVALID");
System.out.println();
catch (NumberFormatException notInt)
System.out.println(fileName);
// String printMessage = notInt.toString().replaceAll("#.*?;", ""); "#" + file +
// ";"
System.out.println(notInt);
System.out.println("INVALID");
System.out.println();
catch (InputMismatchException badContent)
System.out.println(fileName);
System.out.println(badContent);
System.out.println("INVALID");
System.out.println();
catch (IllegalCharacterException delChar)
System.out.println(fileName);
System.out.println(delChar);
System.out.println("INVALID");
System.out.println();
public void readInTextFile(String fileName)
throws FileNotFoundException, IllegalCharacterException, NumberFormatException
File file = new File(fileName);
if (file.exists() && file.isFile())
parseFile(file);
else
throw new FileNotFoundException(fileName);
public void parseFile(File file) throws FileNotFoundException, IllegalCharacterException
Scanner fileScan = new Scanner(file);
String declaredRowCol = fileScan.nextLine().trim();
String[] dimensions = declaredRowCol.split("\s+");
String declaredRowStr = dimensions[0];
String declaredColStr = dimensions[1];
int rowCount = 0;
int colCount = 0;
String notAllNumbers = "";
while (fileScan.hasNextLine())
String line = fileScan.nextLine().trim();
if (!line.isEmpty())
rowCount++;// Counts actual number of rows
Scanner lineScan = new Scanner(line);
while (lineScan.hasNext())
String token = lineScan.next().trim(); // should I include trim?
char letterCheck = token.charAt(0);
// Checks to make sure the content of this file includes only numbers
if (Character.isLetter(letterCheck))
notAllNumbers = letterCheck + "";
colCount++; // Counts actual number of columns, divide by rowCount to get actual
lineScan.close();
// Checks to make sure there is not an extra integer on the first line
if (dimensions.length > 2)
throw new IllegalCharacterException(
"Row and Column have already been provided on the first line of the file. The extra integer: "
+ """ + dimensions[2] + """ + " should not be included.");
else if (!notAllNumbers.isEmpty())
throw new IllegalCharacterException(
"This value in your file: " + """ + notAllNumbers + """ + " is not a number.");
else
formatDimensions(dimensions, declaredRowStr, declaredColStr, rowCount, colCount);
public void formatDimensions(String[] dimensions, String declaredRowStr, String declaredColStr, int rowCount,
int colCount) throws IllegalCharacterException, NumberFormatException, FileNotFoundException
int declaredRow = 0;
int declaredCol = 0;
// Catches if the variables on the first line are of type integer
try
declaredRow = Integer.parseInt(declaredRowStr);
declaredCol = Integer.parseInt(declaredColStr);
fileContent(declaredRow, declaredCol, rowCount, colCount);
catch (NumberFormatException e)
throw new NumberFormatException("This value on the first line of your file:"
+ e.getMessage().substring(17, e.getMessage().length()) + " is not of type integer.");
public void fileContent(int declaredRow, int declaredCol, int rowCount, int colCount)
throws FileNotFoundException, IllegalCharacterException
// Checks to see if row and column matches the actual number of rows and columns
double roundToRealRowCount = (rowCount / 1.0); // This is to account for rounding of
// integer
double roundToRealColCount = (colCount / roundToRealRowCount);// if row or column is not
// divided evenly
if (rowCount != declaredRow)
throw new InputMismatchException("Number of rows declaration: " + "'" + declaredRow + "'"
+ " on first line does not match the actual number of rows in file.");
else if (roundToRealColCount != declaredCol)
throw new InputMismatchException("Number of columns declaration: " + "'" + declaredCol + "'"
+ " on first line does not match the actual number of columns in file.");
java
$endgroup$
This was my original posting: Check that a data file contains the expected number of rows and columns of integers
I updated the code. Still what could I improve on?
Another question I have is how come my last method fileContent() does not need any throws declaration in the method header?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class FormatChecker2
public static void main(String[] args)
FormatChecker2 tester = new FormatChecker2(); // To avoid every method being static.
if (args.length == 0)
System.out.println("Usage: $ java FormatChecker file1 [file2 ... fileN]");
else
for (String fileName : args)
try
tester.readInTextFile(fileName);
System.out.println(fileName + "");
System.out.println("VALID");
System.out.println();
catch (FileNotFoundException notFound)
System.out.println(notFound.getMessage() + "");
System.out.println(notFound + " (The system cannot find the file specified)");
System.out.println("INVALID");
System.out.println();
catch (NumberFormatException notInt)
System.out.println(fileName);
// String printMessage = notInt.toString().replaceAll("#.*?;", ""); "#" + file +
// ";"
System.out.println(notInt);
System.out.println("INVALID");
System.out.println();
catch (InputMismatchException badContent)
System.out.println(fileName);
System.out.println(badContent);
System.out.println("INVALID");
System.out.println();
catch (IllegalCharacterException delChar)
System.out.println(fileName);
System.out.println(delChar);
System.out.println("INVALID");
System.out.println();
public void readInTextFile(String fileName)
throws FileNotFoundException, IllegalCharacterException, NumberFormatException
File file = new File(fileName);
if (file.exists() && file.isFile())
parseFile(file);
else
throw new FileNotFoundException(fileName);
public void parseFile(File file) throws FileNotFoundException, IllegalCharacterException
Scanner fileScan = new Scanner(file);
String declaredRowCol = fileScan.nextLine().trim();
String[] dimensions = declaredRowCol.split("\s+");
String declaredRowStr = dimensions[0];
String declaredColStr = dimensions[1];
int rowCount = 0;
int colCount = 0;
String notAllNumbers = "";
while (fileScan.hasNextLine())
String line = fileScan.nextLine().trim();
if (!line.isEmpty())
rowCount++;// Counts actual number of rows
Scanner lineScan = new Scanner(line);
while (lineScan.hasNext())
String token = lineScan.next().trim(); // should I include trim?
char letterCheck = token.charAt(0);
// Checks to make sure the content of this file includes only numbers
if (Character.isLetter(letterCheck))
notAllNumbers = letterCheck + "";
colCount++; // Counts actual number of columns, divide by rowCount to get actual
lineScan.close();
// Checks to make sure there is not an extra integer on the first line
if (dimensions.length > 2)
throw new IllegalCharacterException(
"Row and Column have already been provided on the first line of the file. The extra integer: "
+ """ + dimensions[2] + """ + " should not be included.");
else if (!notAllNumbers.isEmpty())
throw new IllegalCharacterException(
"This value in your file: " + """ + notAllNumbers + """ + " is not a number.");
else
formatDimensions(dimensions, declaredRowStr, declaredColStr, rowCount, colCount);
public void formatDimensions(String[] dimensions, String declaredRowStr, String declaredColStr, int rowCount,
int colCount) throws IllegalCharacterException, NumberFormatException, FileNotFoundException
int declaredRow = 0;
int declaredCol = 0;
// Catches if the variables on the first line are of type integer
try
declaredRow = Integer.parseInt(declaredRowStr);
declaredCol = Integer.parseInt(declaredColStr);
fileContent(declaredRow, declaredCol, rowCount, colCount);
catch (NumberFormatException e)
throw new NumberFormatException("This value on the first line of your file:"
+ e.getMessage().substring(17, e.getMessage().length()) + " is not of type integer.");
public void fileContent(int declaredRow, int declaredCol, int rowCount, int colCount)
throws FileNotFoundException, IllegalCharacterException
// Checks to see if row and column matches the actual number of rows and columns
double roundToRealRowCount = (rowCount / 1.0); // This is to account for rounding of
// integer
double roundToRealColCount = (colCount / roundToRealRowCount);// if row or column is not
// divided evenly
if (rowCount != declaredRow)
throw new InputMismatchException("Number of rows declaration: " + "'" + declaredRow + "'"
+ " on first line does not match the actual number of rows in file.");
else if (roundToRealColCount != declaredCol)
throw new InputMismatchException("Number of columns declaration: " + "'" + declaredCol + "'"
+ " on first line does not match the actual number of columns in file.");
java
java
edited Sep 19 '17 at 0:09
dporth
asked Sep 19 '17 at 0:03
dporthdporth
123
123
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 5 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
$begingroup$
...but I see fileContent method does havethrows
clause ....
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:32
$begingroup$
all the printing inside the catch clauses look very similar. should be put in a method.
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:34
add a comment |
$begingroup$
...but I see fileContent method does havethrows
clause ....
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:32
$begingroup$
all the printing inside the catch clauses look very similar. should be put in a method.
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:34
$begingroup$
...but I see fileContent method does have
throws
clause ....$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:32
$begingroup$
...but I see fileContent method does have
throws
clause ....$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:32
$begingroup$
all the printing inside the catch clauses look very similar. should be put in a method.
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:34
$begingroup$
all the printing inside the catch clauses look very similar. should be put in a method.
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:34
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
You could use the split method in the String class to count the columns.
String[] columns = line.split(SEPARATOR);
int colCount = columns.length.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f176021%2fread-in-a-file-check-that-it-meets-certain-criteria%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
You could use the split method in the String class to count the columns.
String[] columns = line.split(SEPARATOR);
int colCount = columns.length.
$endgroup$
add a comment |
$begingroup$
You could use the split method in the String class to count the columns.
String[] columns = line.split(SEPARATOR);
int colCount = columns.length.
$endgroup$
add a comment |
$begingroup$
You could use the split method in the String class to count the columns.
String[] columns = line.split(SEPARATOR);
int colCount = columns.length.
$endgroup$
You could use the split method in the String class to count the columns.
String[] columns = line.split(SEPARATOR);
int colCount = columns.length.
edited Aug 19 '18 at 20:30
Stephen Rauch
3,77061630
3,77061630
answered Aug 19 '18 at 19:56
fpezzinifpezzini
1067
1067
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f176021%2fread-in-a-file-check-that-it-meets-certain-criteria%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
...but I see fileContent method does have
throws
clause ....$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:32
$begingroup$
all the printing inside the catch clauses look very similar. should be put in a method.
$endgroup$
– Sharon Ben Asher
Sep 19 '17 at 6:34