我有一个包含此文本的文件
@Entity
@Table(name = "User")
public class User implements LSLEntity, HasUUID {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = "facebook_id", unique=true)
private String facebookId;
@UUID
@Column(name = "uuid", unique = true)
private String uuid;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="user_info_id")
private UserInfo userInfo;
@OneToOne
@JoinColumn(name="balanced_customer_id")
@Transient
private BalancedCustomer balancedCustomer;
@OneToOne(mappedBy = "user")
private Session session;
我需要清理文件中的注释。我编写了一个简单的 Java 程序,用于从文件下载数据
public class Test {
public static void main(String[] args) throws IOException {
File file = new File( "C:\\test.txt" );
BufferedReader br = new BufferedReader (new InputStreamReader(new FileInputStream( file ), "UTF-8"));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println( line );
}
br.close();
}
}
现在,我需要清理注释中的数据以最终发生
public class User implements LSLEntity, HasUUID {
private Long id;
private String facebookId;
private String uuid;
private UserInfo userInfo;
private BalancedCustomer balancedCustomer;
private Session session;
我想使用正则表达式。请告诉我一篇好的文章,或者例子,或者它可能有另一种解决问题的方法?
最佳答案
为什么要麻烦java呢?只需从命令行运行 grep -v ^@ [yourfile.java]
即可。
[编辑]
grep:
-v means invert-match: Selected lines are those not matching any of the specified patterns.
^
表示匹配行首。这将匹配以 @
顺便说一句,你也可以尝试 sed:
sed '/^@/d' 测试
关于java - 如何清除文件中的注释? (也许是正则表达式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28103567/