java
1import java.io.BufferedReader; 2import java.io.BufferedWriter; 3import java.io.IOException; 4import java.nio.charset.Charset; 5import java.nio.file.Files; 6import java.nio.file.Paths; 7import java.util.List; 8import java.util.stream.Collectors; 9 10public class Remove { 11 12 public static String altsdir; 13 14 15 public static void main(String[] args) throws IOException { 16 remove(); 17 } 18 19 public static void remove() throws IOException { 20 List<String>list=null; 21 try(BufferedReader br=Files.newBufferedReader(Paths.get("doc.txt"),Charset.forName("MS932"))){ 22 list=br.lines().collect(Collectors.toList()); 23 System.out.println("read"); 24 } 25 for(int a = 0; a < 7; ++a) { 26 list.remove(a); 27 System.out.println("remove"); 28 } 29 try(BufferedWriter bw=Files.newBufferedWriter(Paths.get("doc.txt"),Charset.forName("MS932"))){ 30 list.stream().forEach(line->{ 31 try { 32 bw.write(line); 33 bw.newLine(); 34 } catch (Exception e) { 35 e.printStackTrace(); 36 } 37 }); 38 } 39 } 40}
doc.txtは
1
2
3
4
5....
というようなのですがどこが悪いのでしょうか?
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。