Append a record to the end of a text file: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (remove bogus template markup) |
(→{{header|Java}}: code cleanup, consistent indentation) |
||
Line 1,380: | Line 1,380: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
⚫ | |||
⚫ | |||
import static java.lang.Integer.parseInt; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
import static java.util.stream.Collectors.toList; |
|||
import java.io.IOException; |
import java.io.IOException; |
||
Line 1,393: | Line 1,386: | ||
import java.nio.file.Path; |
import java.nio.file.Path; |
||
import java.nio.file.Paths; |
import java.nio.file.Paths; |
||
⚫ | |||
⚫ | |||
⚫ | |||
import java.util.List; |
import java.util.List; |
||
⚫ | |||
import java.util.stream.Stream; |
import java.util.stream.Stream; |
||
public class RecordAppender { |
public class RecordAppender { |
||
static class Record { |
static class Record { |
||
private final String account; |
private final String account; |
||
private final String password; |
private final String password; |
||
private final int uid; |
private final int uid; |
||
private final int gid; |
private final int gid; |
||
private final List<String> gecos; |
private final List<String> gecos; |
||
private final String directory; |
private final String directory; |
||
private final String shell; |
private final String shell; |
||
public Record(String account, String password, int uid, int gid, List<String> gecos, String directory, String shell) { |
public Record(String account, String password, int uid, int gid, List<String> gecos, String directory, String shell) { |
||
this.account = requireNonNull(account); |
this.account = requireNonNull(account); |
||
this.password = requireNonNull(password); |
this.password = requireNonNull(password); |
||
this.uid = uid; |
this.uid = uid; |
||
this.gid = gid; |
this.gid = gid; |
||
this.gecos = requireNonNull(gecos); |
this.gecos = requireNonNull(gecos); |
||
this.directory = requireNonNull(directory); |
this.directory = requireNonNull(directory); |
||
this.shell = requireNonNull(shell); |
this.shell = requireNonNull(shell); |
||
⚫ | |||
⚫ | |||
public String toString() { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Integer.parseInt(tokens[3]), |
|||
⚫ | |||
⚫ | |||
tokens[6]); |
|||
⚫ | |||
} |
} |
||
⚫ | |||
⚫ | |||
List<String> rawData = Arrays.asList( |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Path tmp = Paths.get("_rosetta", ".passwd"); |
|||
Files.createDirectories(tmp.getParent()); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
} |
|||
⚫ | |||
String[] rawData = { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Path tmp = Paths.get("_rosetta", ".passwd"); |
|||
Files.createDirectories(tmp.getParent()); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
⚫ | |||
} |
|||
} |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>Appended Record: xyz:x:1003:1000:X Yz,Room 1003,(234)555-8913,(234)555-0033,xyz@rosettacode.org:/home/xyz:/bin/bash</pre> |
<pre>Appended Record: xyz:x:1003:1000:X Yz,Room 1003,(234)555-8913,(234)555-0033,xyz@rosettacode.org:/home/xyz:/bin/bash</pre> |