我有Java String ôð¤ Ø$î1<¨ V¸dPžÐ ÀH@ˆàÀༀ@~€4`,我想用ANSI编码写一个文件.
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output),"windows-1252"));
try {
out.append(str);
} finally {
out.close();
}
Run Code Online (Sandbox Code Playgroud)
调试器说str包含ôð¤ Ø$î1<¨ V¸dPÐ ÀH@àÀà¼@~4.只要我将其写入输出文件,该文件只包含?ÒÜ@4.那么我的方法写入文件有什么问题?
对不起这个奇怪的字符串 - 我试图在java中重写一个delphi 7函数.这些字符串是我得到的唯一样本.
我在System课堂上发现了这个,但我想知道这是如何实现的.
/**
* System properties. The following properties are guaranteed to be defined:
* <dl>
* <dt>java.version <dd>Java version number
* <dt>java.vendor <dd>Java vendor specific string
* <dt>java.vendor.url <dd>Java vendor URL
* <dt>java.home <dd>Java installation directory
* <dt>java.class.version <dd>Java class version number
* <dt>java.class.path <dd>Java classpath
* <dt>os.name <dd>Operating System Name
* <dt>os.arch <dd>Operating System Architecture
* <dt>os.version <dd>Operating System Version
* <dt>file.separator <dd>File separator ("/" on Unix)
* <dt>path.separator <dd>Path separator (":" on Unix)
* <dt>line.separator <dd>Line …Run Code Online (Sandbox Code Playgroud) 是否有任何可用的 Java api 可以帮助模拟正在使用的固定内存量?
我正在构建一个虚拟应用程序,其方法中不包含任何实现。我想要在这个方法中做的就是模拟一定量的内存被用完——这可能吗?
我试图从我的具有try-catch块的函数返回一个布尔值,
但问题是我无法回报任何价值.
我知道try-catch块中的变量不能在它之外访问但仍然是我想要的.
public boolean checkStatus(){
try{
InputStream fstream = MyRegDb.class.getClassLoader().getResourceAsStream("textfile.txt");
// Use DataInputStream to read binary NOT text.
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
strLine = br.readLine();
// Print the content on the console
System.out.println (strLine);
ind.close();
if(strLine.equals("1")){
return false;
}else{
return true;
}
}catch(Exception e){}
}
Run Code Online (Sandbox Code Playgroud)
在我的项目中,这对我来说是一个非常严重的问题.我用谷歌搜索,并尝试自己,但没有解决.
我希望现在我会找到一些解决方案.我知道它有错误说返回语句丢失 但我希望程序完全像这样工作.
现在我对此严格的原因
在我的jar文件中,我必须访问文本文件以查找值1或0,如果为"1",则激活其他取消激活.
这就是我使用布尔值的原因.
我需要编写一个代码,该代码对产品的几行评论作为输入,并根据描述评论中产品的形容词对产品进行评级.我刚刚使用POS标签来标记每条评论的词性.现在,我必须挑选出描述名词的形容词,如果名词似乎与产品有关,我需要考虑相应的形容词.这是我用于POS标记的代码..它工作正常.
import java.io.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class Tagg {
public static void main(String[] args) throws IOException,
ClassNotFoundException {
String tagged;
// Initialize the tagger
MaxentTagger tagger = new MaxentTagger("edu/stanford/nlp/models/pos-tagger/wsj- left3words/wsj-0-18-left3words-distsim.tagger");
FileInputStream fstream = new FileInputStream("src/input.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
FileWriter q = new FileWriter("src/output.txt",true);
BufferedWriter out =new BufferedWriter(q);
String sample;
//we will now pick up sentences line by line from the file input.txt and store it in the string sample
while((sample = br.readLine())!=null)
{
//tag the string
tagged …Run Code Online (Sandbox Code Playgroud) 我有一个java调用windows bat文件,它执行一些处理并生成输出文件.
Process p = Runtime.getRuntime().exec("cmd /c "+filename);
现在从以下程序中读取文件.(filexists()是检查文件是否存在的功能).输出文件仅包含单行
if ( filexists("output.txt") == true)
{ String FileLine;
FileInputStream fstream = new FileInputStream("output.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
FileLine = br.readLine();
fstream.close();
filein.close();
}
Run Code Online (Sandbox Code Playgroud)
变量FileLine在起始时包含3个垃圾字符.我还检查了progam中的其他几个文件,没有文件有这个问题,除了它是用Runtime函数创建的.
9087.
正如您所看到的那样,输出文件中会出现三个垃圾字符.用Notepad ++打开时,我无法看到那些垃圾字符.
请建议
我想在JVM崩溃时收集堆转储
所以我写了一个简单的代码
public class Test {
private String name;
public Test(String name) {
this.name = name;
}
public void execute() {
Map<String,String> randomData = new HashMap<String,String>();
for(int i=0;i<1000000000;i++) {
randomData.put("Key:" + i,"Value:" + i);
}
}
public void addData() {
}
public static void main(String args[]) {
String myName = "Aniket";
Test tStart = new Test(myName);
tStart.execute();
}
}
Run Code Online (Sandbox Code Playgroud)
我按如下方式运行它
[aniket@localhost Desktop]$ java -cp . -Xms2m -Xmx2m Test
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at Test.execute(Test.java:15)
at Test.main(Test.java:25) …Run Code Online (Sandbox Code Playgroud) 在Java中,Deque该类具有实际返回返回元素的末尾的删除方法.在C++中,似乎实现相同行为的唯一方法是首先显式复制元素然后弹出它.
std::deque<int> myDeque;
myDeque.push_back(5);
int element = myDeque.back();
myDeque.pop_back();
Run Code Online (Sandbox Code Playgroud)
是否有同时进行这两种机制的机制?
我有以下代码来测试:
import java.math.BigInteger;
import java.util.Random;
public class TestBigInteger {
public static void main(String[] args) {
BigInteger bigInteger = BigInteger.probablePrime(32, new Random())
.multiply(BigInteger.probablePrime(32, new Random()));
BigInteger n = BigInteger.probablePrime(20, new Random());
while (!Thread.interrupted()) {
bigInteger.mod(n);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我从jconsole得到了以下情节:
为什么会这样?如果我bigInteger只有64位长度,为什么mod操作会占用大量内存?
在C和C++中,我知道在堆栈上实例化对象与使用"new"在堆上创建对象之间的性能可能会有很大差异.
这在Java中是一样的吗?
Java中的"new"运算符非常方便(特别是当我不必记住释放/删除使用"new"创建的对象时),但这是否意味着我可以疯狂地使用'new'?
java ×9
jvm ×2
memory ×2
biginteger ×1
c++ ×1
c++11 ×1
delphi ×1
deque ×1
encoding ×1
file-io ×1
heap-dump ×1
jconsole ×1
jvm-crash ×1
native ×1
new-operator ×1
nlp ×1
performance ×1
pos-tagger ×1
properties ×1
return ×1
return-value ×1
stanford-nlp ×1
try-catch ×1