How to know file size from bytes [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have byte array, how to know file size ? (in JAVA)
File file = new File("patch");
file.length() // <--- it's good, but I haven't original file... (( I get file in bytes from DataBase !
Thanks

You have an array with you and every array has a length. That's it.
byteArray.length;
And
1kb = 1024 bytes

Related

How to display a portion of a string at an index of a string array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof

How to create substring from string at specific fixed length [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have java String with more than 160 character, on that i want to create substring form that string for first 150 character.
I have google it for that but what i got is for make substring at special character.
Please show me possible way for do this..
String#substring(int beginIndex, int endIndex) is what you need.
String mySubString = myString.substring(0, 150);

How to read a file in java element by element [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a file which's structure is
#n aa bb cc
Where n is the number of elements in the row, and aa is an element(there's always space between them).
So I would like to know of there's a way to read the n and then element by element during some rows.
Here's one solution:
Read the file in line at a time
Split the line by space
["#n", "aa", "bb", "cc"]
take the substring of the first element to exclude the # and parse an integer from it
Java has built in support for Regular Expressions using java.util.regex.Pattern and java.util.regex.Matcher. These are the tools you need.

How can I read a single word from a txt file and make it a variable in my code? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a text file with a single word say "fish " but it will have spaces after the word. is there anyway I can pull the word fish as a variable but leave off the spaces?
Scanner in = new Scanner(new File("path_to_file.txt"));
String var = in.next();
var = var.trim();
in.close();
Not the most efficient way, but one of the simplest.
string Text = File.ReadAllText("path_to_file.txt").trim();

How to store long range number [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have to store this value.but eclipse shows error on that.
private final long cal_To_eV = 26131952998320000000L;
plz tell me how to store this.
Have a look at the class BigInteger.
You can use String not long. Also you can use BigInteger or BigDouble.
private final BigInteger cal_To_eV = new BigInteger("26131952998320000000");

Categories