Created
February 18, 2013 08:23
-
-
Save stden/4975869 to your computer and use it in GitHub Desktop.
Чтение параметров устройства
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package converttodb; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.UnsupportedEncodingException; | |
import java.util.Scanner; | |
/** | |
* Разбор описания одного устройства (из текстового файла в объект). | |
* На входе - текстовый файл. | |
* На выходе обьект класса DeviceParams с заполненными полями. | |
*/ | |
public class DeviceParams { | |
public String name; | |
public String deviceType; | |
public String OS; | |
public String Dimensions; | |
public String Weight; | |
/** | |
* @param fileName Файл с описанием устройства | |
*/ | |
public DeviceParams(String fileName) throws FileNotFoundException, UnsupportedEncodingException { | |
Scanner scanner = new Scanner(new File(fileName)); | |
while (scanner.hasNextLine()) { // Пока входной файл не кончился | |
String s = scanner.nextLine().trim(); // Читаем очередную строку | |
if (name == null) // В первой строке имя устройства? | |
name = s; | |
if (s.equals("Device type:")) | |
deviceType = scanner.nextLine().trim(); | |
if (s.equals("OS:")) | |
OS = scanner.nextLine().trim(); | |
if (s.equals("Dimensions:")) | |
Dimensions = scanner.nextLine().trim(); | |
if (s.equals("Weight:")) | |
Weight = scanner.nextLine().trim(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment