import java.io.BufferedWriter
import java.io.FileReader
import java.io.FileWriter
import java.io.IOException
public class Test14 {
public static void main(String[] args) throws IOException {
String fPath = "C:/test.txt"
// 读
BufferedReader br = new BufferedReader(new FileReader(fPath))
System.out.println(br.readLine())
br.close()// // 使用后记得关闭
// 写
BufferedWriter bw = new BufferedWriter(new FileWriter(fPath))
bw.flush()
bw.close()// 使用后记得关闭
}
}
import java.io.File
import java.io.FileWriter
import java.io.IOException
import java.util.Scanner
public class YuGiOh
{
private static final String LINE = System.getProperty ("line.separator")
private static final String FILE = "io.txt"
private static final String RESULT = "result.txt"
private static final int LEVEL = 48
/**
* 读取文件某一行
*/
private static String readFile ( String file, int line )
{
Scanner scanner = null
try
{
scanner = new Scanner (new File (file))
scanner.skip ("([^" + LINE + "]+" + LINE + "){" + ( line - 1 ) + "}")
if (scanner.hasNextLine ())
{
return scanner.nextLine ()
}
}
catch (Exception ignore)
{}
finally
{
if (null != scanner)
{
scanner.close ()
}
}
return ""
}
private static void writeFile ( String file, String line )
{
FileWriter fw = null
try
{
fw = new FileWriter (file)
fw.write (line)
fw.flush ()
}
catch (IOException e)
{
e.printStackTrace ()
}
finally
{
if (null != fw)
{
try
{
fw.close ()
}
catch (IOException ignore)
{}
}
}
}
public static void main ( String[] args )
{
String line = ""
int count = 1
int one = 0, two = 0
while (!"".equals (line = readFile (FILE, count++)))
{
String[] array = line.split ("\\s+")
int num = Integer.parseInt (array[0].trim ())
int price = Integer.parseInt (array[1].trim ())
if (num < LEVEL)
{
one += price
}
else if (num > LEVEL)
{
two += price
}
}
int max = 0, min = 0
max = one > two ? one : two
min = one < two ? one : two
String result = "high_price\t\t" + max + LINE + "low_price\t\t" + min
writeFile (RESULT, result)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)