In java, it was fisfos as below ...
package fileconvert;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Convert {
public static void main(String[] args) throws IOException{
//Read file
FileInputStream fis=new FileInputStream("assets/sample.txt");
InputStreamReader isr=new InputStreamReader(fis,"sjis");
BufferedReader br=new BufferedReader(isr);
//Writing a file
FileOutputStream fos=new FileOutputStream("assets/sample2.txt");
OutputStreamWriter osw=new OutputStreamWriter(fos,"utf-8");
BufferedWriter bw=new BufferedWriter(osw);
String line;
while((line=br.readLine())!=null) {
bw.append(line);
bw.newLine();
}
br.close();
bw.flush();
bw.close();
System.out.println("done!");
/*
while(true) {
String line=br.readLine();
if(line == null) {
break;
}
System.out.println(line);
}
*/
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WeightApp
{
class Program
{
static void Main(string[] args)
{
var path=@"./log.txt";
while (true)
{
Console.WriteLine("Please enter the operation Please enter the operation 1...Enter your weight, 2...See list, 3...End>");
var select = Console.ReadLine();
switch (select)
{
case "1":
Console.Write("Please enter your weight>");
var weight = double.Parse(Console.ReadLine());
using (var writer = new StreamWriter(path, true))
{
writer.WriteLine($"{DateTime.Now.ToString()} {weight}kg");
}
break;
case "2":
var file = new FileInfo(path);
//Is there or not
if (file.Exists)
{
using (var reader = new StreamReader(path))
{
string line;
while ((line = reader.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
else
{
Console.WriteLine("There is no data yet.");
}
break;
default:
Console.WriteLine("Exit the app.");
return;
}
}
}
}
}
It is recognition. I'm not proud, but only fisfos can understand the mechanism and memorize it.
It's a mystery myself. ..
Recommended Posts