|
no probs, here's the source and results
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ReadTextFile
{
public static void main(String[] args)
{
File file = new File("c:\\myjava\\test.txt");
StringBuffer contents = new StringBuffer();
BufferedReader reader = null;
try
{
reader = new BufferedReader(new FileReader(file));
String text = null;
while ((text = reader.readLine()) != null)
{
contents.append(text)
.append(System.getProperty("line.separator"));
}
} catch (FileNotFoundException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
} finally
{
try
{
if (reader != null)
{
reader.close();
}
} catch (IOException e)
{
e.printStackTrace();
}
}
String text = contents.toString();
System.out.println(text);
char[] textArray = new char[3];
text.getChars(9, 12, textArray, 0);
System.out.println(textArray);
int difx;
difx=Integer.parseInt(text);
System.out.println(difx+1);
}
}
And the error outputs:
The current directory is: @MyProjects
61541116546878646541321357687461351354638541351864 1 <-- this is the full number in my text file
468 <-- the getChars numbers
Exception in thread "main" java.lang.NumberFormatException: For input string: "6154111654687864654132135768746135135463854135186 41
"
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:459)
at java.lang.Integer.parseInt(Integer.java:497)
at ReadTextFile.main(ReadTextFile.java:57)
Interactive Session Ended
What do you think?
|