[Solved] How to read portions of text from a .txt file in Java?

You can use Scanner class, which provides a Scanner#nextInt() method to read the next token as int. Now, since your integers are comma(,) separated, you need to set comma(,) as delimiter in your Scanner, which uses whitespace character as default delimiter. You need to use Scanner#useDelimiter(String) method for that. You can use the following code: … Read more

[Solved] How to read txt file, and use the double values in it?

You can try that code import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class MainActivity extends AppCompatActivity { AudioAnalyzer aa = new AudioAnalyzer(); TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = (TextView) findViewById(R.id.textView); } public void analyzer (View view) throws FileNotFoundException{ try { double[] input = … Read more

[Solved] Reading a text file in python [closed]

Here is an example of reading and writing a text file below. I believe that you are looking for the “open” method. with open(‘New_Sample.txt’, ‘w’) as f_object: f_object.write(‘Python sample!\n’) f_object.write(‘Another line!\n’) You simple open the file that you want and enter that file name as the first argument, and then you use ‘w’ as the … Read more

[Solved] Read Certain Data from text File

You can use Regex with LINQ to compare the Date format data type. CODE // Regex pattern to match DD.MM.YYYY Format var regexPattern = @”^([0]?[0-9]|[12][0-9]|[3][01])[.]([0]?[1-9]|[1][0-2])[.]([0-9]{4}|[0-9]{2})$”; Regex regexObj = new Regex(regexPattern); // Matched Values matching the regex pattern are returned in IENUMERABLE OF STRING TYPE var dates = File.ReadLines(txtFilePath).Select(lines => lines.Split(‘ ‘).FirstOrDefault(colValue => regexObj.IsMatch(colValue))); 7 solved … Read more

[Solved] Python: Reading marks from a file then using marks to get class

import csv # function to process data def process_data(data): for item in data: marks = int(item[2]) mclass=”incorrect data entry try again” if marks == 0: mclass = “10.9” elif marks >= 0 and marks <= 100: mclass = “10.{}”.format(10 – int(item[2][0])) yield ‘”{}”,”{}”,{},{}’.format(item[0],item[1],item[2],mclass) # read data to memory data = [] with open(“Maths_Mark.txt”, “r”) as … Read more